Skip to content

Commit e354fb7

Browse files
committed
import cloudflare load-balancers to terraform
1 parent 8610b62 commit e354fb7

File tree

5 files changed

+347
-0
lines changed

5 files changed

+347
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
cloud {
3+
organization = "subspace-sre"
4+
5+
workspaces {
6+
name = "cloudflare-load-balancers"
7+
}
8+
}
9+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# This script imports Cloudflare Load Balancer resources into Terraform state.
3+
4+
# Import RPC Mainnet Health Check
5+
terraform import cloudflare_load_balancer_monitor.rpc_mainnet_health_check a0c2610e19310a13e355eb50fe041a97/80e2b143f1b4553b05c54f5de582427d
6+
7+
# Import RPC Taurus Health Check
8+
terraform import cloudflare_load_balancer_monitor.rpc_taurus_health_check a0c2610e19310a13e355eb50fe041a97/d4169f7b3fe896287bc127191c03bd62
9+
10+
# Import RPC Taurus EVM Health Check
11+
terraform import cloudflare_load_balancer_monitor.rpc_taurus_evm_health_check a0c2610e19310a13e355eb50fe041a97/c22a1414ec304fb46d37f95bac2b731a
12+
13+
# Import Mainnet-RPC pool
14+
terraform import cloudflare_load_balancer_pool.mainnet_rpc a0c2610e19310a13e355eb50fe041a97/0e3fdc24211b5a232023db3fc68002bd
15+
16+
# Import Taurus-RPC pool
17+
terraform import cloudflare_load_balancer_pool.taurus_rpc a0c2610e19310a13e355eb50fe041a97/488cd954504a0285f6e347417363062f
18+
19+
# Import Taurus-RPC-EVM pool
20+
terraform import cloudflare_load_balancer_pool.taurus_rpc_evm a0c2610e19310a13e355eb50fe041a97/004df046e23db27f92a16ccb9cc50e30
21+
22+
# Import Taurus-RPC-EVM-Fallback pool
23+
terraform import cloudflare_load_balancer_pool.taurus_rpc_evm_fallback a0c2610e19310a13e355eb50fe041a97/ff295017c1ab46525b24fcde5b00eed1
24+
25+
# Import auto-evm-lb.taurus.autonomys.xyz
26+
terraform import cloudflare_load_balancer.auto_evm_lb_taurus c2b6ccca486f046dac214ee6eaa8295a/4a7e075cae7abf7e9d70d6e27abccac1
27+
28+
# Import rpc-lb.mainnet.autonomys.xyz
29+
terraform import cloudflare_load_balancer.rpc_lb_mainnet c2b6ccca486f046dac214ee6eaa8295a/f38ef4ef1fc28508c2004f9756635ea1
30+
31+
# Import rpc-lb.taurus.autonomys.xyz
32+
terraform import cloudflare_load_balancer.rpc_lb_taurus c2b6ccca486f046dac214ee6eaa8295a/0babbfbb55a1a2f18dcc15cd66554f5c
Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
# Cloudflare Provider Configuration
2+
terraform {
3+
required_providers {
4+
cloudflare = {
5+
source = "cloudflare/cloudflare"
6+
version = "~> 4.0"
7+
}
8+
}
9+
}
10+
11+
provider "cloudflare" {
12+
api_token = var.cloudflare_api_token
13+
}
14+
15+
16+
# =============================================================================
17+
# MONITORS (Import these first)
18+
# =============================================================================
19+
20+
# Monitor 1: RPC Mainnet Health Check
21+
resource "cloudflare_load_balancer_monitor" "rpc_mainnet_health_check" {
22+
account_id = var.cloudflare_account_id
23+
type = "tcp"
24+
port = 30333
25+
interval = 60
26+
retries = 2
27+
timeout = 5
28+
method = "connection_established"
29+
description = "RPC Mainnet Health Check"
30+
}
31+
32+
# Monitor 2: RPC Taurus Health Check
33+
resource "cloudflare_load_balancer_monitor" "rpc_taurus_health_check" {
34+
account_id = var.cloudflare_account_id
35+
type = "tcp"
36+
port = 30333
37+
interval = 60
38+
retries = 2
39+
timeout = 5
40+
method = "connection_established"
41+
description = "RPC Taurus Health Check"
42+
}
43+
44+
# Monitor 3: RPC Taurus EVM Health Check
45+
resource "cloudflare_load_balancer_monitor" "rpc_taurus_evm_health_check" {
46+
account_id = var.cloudflare_account_id
47+
type = "tcp"
48+
port = 30333
49+
interval = 60
50+
retries = 2
51+
timeout = 5
52+
method = "connection_established"
53+
description = "RPC Taurus EVM Health Check"
54+
}
55+
56+
# =============================================================================
57+
# POOLS (Import these second)
58+
# =============================================================================
59+
60+
# Pool 1: Mainnet-RPC
61+
resource "cloudflare_load_balancer_pool" "mainnet_rpc" {
62+
account_id = var.cloudflare_account_id
63+
name = "Mainnet-RPC"
64+
description = "Mainnet RPC"
65+
enabled = true
66+
minimum_origins = 2
67+
monitor = cloudflare_load_balancer_monitor.rpc_mainnet_health_check.id
68+
check_regions = ["ENAM"]
69+
70+
origins {
71+
name = "rpc-0.mainnet"
72+
address = "54.82.252.177"
73+
enabled = true
74+
weight = 0.5
75+
}
76+
77+
origins {
78+
name = "rpc-1.mainnet"
79+
address = "52.90.85.214"
80+
enabled = true
81+
weight = 0.5
82+
}
83+
84+
}
85+
86+
# Pool 2: Taurus-RPC
87+
resource "cloudflare_load_balancer_pool" "taurus_rpc" {
88+
account_id = var.cloudflare_account_id
89+
name = "Taurus-RPC"
90+
description = ""
91+
enabled = true
92+
minimum_origins = 2
93+
monitor = cloudflare_load_balancer_monitor.rpc_taurus_health_check.id
94+
check_regions = ["WEU"]
95+
96+
origin_steering {
97+
policy = "random"
98+
}
99+
100+
origins {
101+
name = "rpc-0-taurus"
102+
address = "52.91.1.29"
103+
enabled = true
104+
weight = 0.5
105+
}
106+
107+
origins {
108+
name = "rpc-1-taurus"
109+
address = "174.129.155.116"
110+
enabled = true
111+
weight = 0.5
112+
}
113+
114+
}
115+
116+
# Pool 3: Taurus-RPC-EVM
117+
resource "cloudflare_load_balancer_pool" "taurus_rpc_evm" {
118+
account_id = var.cloudflare_account_id
119+
name = "Taurus-RPC-EVM"
120+
description = ""
121+
enabled = true
122+
minimum_origins = 1
123+
monitor = cloudflare_load_balancer_monitor.rpc_taurus_evm_health_check.id
124+
check_regions = ["WNAM"]
125+
126+
origin_steering {
127+
policy = "random"
128+
}
129+
130+
origins {
131+
name = "auto-evm-1"
132+
address = "18.234.222.92"
133+
enabled = true
134+
weight = 0.5
135+
}
136+
137+
origins {
138+
name = "auto-evm-3"
139+
address = "65.108.232.15"
140+
enabled = false
141+
weight = 0.5
142+
}
143+
144+
}
145+
146+
# Pool 4: Taurus-RPC-EVM-Fallback
147+
resource "cloudflare_load_balancer_pool" "taurus_rpc_evm_fallback" {
148+
account_id = var.cloudflare_account_id
149+
name = "Taurus-RPC-EVM-Fallback"
150+
description = "Taurus Auto-EVM RPC LB"
151+
enabled = true
152+
minimum_origins = 1
153+
monitor = cloudflare_load_balancer_monitor.rpc_taurus_evm_health_check.id
154+
check_regions = ["WNAM"]
155+
156+
origins {
157+
name = "auto-evm-0"
158+
address = "34.238.40.85"
159+
enabled = true
160+
weight = 0.25
161+
}
162+
163+
origins {
164+
name = "auto-evm-2"
165+
address = "65.108.232.16"
166+
enabled = false
167+
weight = 0.75
168+
}
169+
170+
}
171+
172+
# =============================================================================
173+
# LOAD BALANCERS (Import these last)
174+
# =============================================================================
175+
176+
# Load Balancer 1: auto-evm-lb.taurus.autonomys.xyz
177+
resource "cloudflare_load_balancer" "auto_evm_lb_taurus" {
178+
zone_id = var.cloudflare_zone_id
179+
name = "auto-evm-lb.taurus.autonomys.xyz"
180+
description = ""
181+
proxied = true
182+
enabled = true
183+
session_affinity = "none"
184+
steering_policy = "random"
185+
fallback_pool_id = cloudflare_load_balancer_pool.taurus_rpc_evm_fallback.id
186+
187+
default_pool_ids = [
188+
cloudflare_load_balancer_pool.taurus_rpc_evm.id,
189+
cloudflare_load_balancer_pool.taurus_rpc_evm_fallback.id
190+
]
191+
192+
session_affinity_attributes {
193+
samesite = "Auto"
194+
secure = "Auto"
195+
drain_duration = 180
196+
zero_downtime_failover = "sticky"
197+
}
198+
199+
adaptive_routing {
200+
failover_across_pools = true
201+
}
202+
203+
random_steering {
204+
default_weight = 1
205+
}
206+
207+
location_strategy {
208+
prefer_ecs = "proximity"
209+
mode = "pop"
210+
}
211+
212+
}
213+
214+
# Load Balancer 2: rpc-lb.mainnet.autonomys.xyz
215+
resource "cloudflare_load_balancer" "rpc_lb_mainnet" {
216+
zone_id = var.cloudflare_zone_id
217+
name = "rpc-lb.mainnet.autonomys.xyz"
218+
description = "Mainnet RPC consensus load-balancer"
219+
proxied = true
220+
enabled = true
221+
session_affinity = "none"
222+
steering_policy = "random"
223+
fallback_pool_id = cloudflare_load_balancer_pool.mainnet_rpc.id
224+
225+
default_pool_ids = [
226+
cloudflare_load_balancer_pool.mainnet_rpc.id
227+
]
228+
229+
session_affinity_attributes {
230+
samesite = "Auto"
231+
secure = "Auto"
232+
drain_duration = 0
233+
zero_downtime_failover = "none"
234+
}
235+
236+
adaptive_routing {
237+
failover_across_pools = false
238+
}
239+
240+
random_steering {
241+
default_weight = 1
242+
}
243+
244+
location_strategy {
245+
prefer_ecs = "proximity"
246+
mode = "pop"
247+
}
248+
249+
}
250+
251+
# Load Balancer 3: rpc-lb.taurus.autonomys.xyz
252+
resource "cloudflare_load_balancer" "rpc_lb_taurus" {
253+
zone_id = var.cloudflare_zone_id
254+
name = "rpc-lb.taurus.autonomys.xyz"
255+
description = ""
256+
proxied = true
257+
enabled = true
258+
session_affinity = "ip_cookie"
259+
session_affinity_ttl = 259200
260+
steering_policy = "random"
261+
fallback_pool_id = cloudflare_load_balancer_pool.taurus_rpc.id
262+
263+
default_pool_ids = [
264+
cloudflare_load_balancer_pool.taurus_rpc.id
265+
]
266+
267+
session_affinity_attributes {
268+
samesite = "Auto"
269+
secure = "Auto"
270+
drain_duration = 3600
271+
zero_downtime_failover = "sticky"
272+
}
273+
274+
adaptive_routing {
275+
failover_across_pools = false
276+
}
277+
278+
random_steering {
279+
default_weight = 1
280+
}
281+
282+
location_strategy {
283+
prefer_ecs = "proximity"
284+
mode = "pop"
285+
}
286+
287+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cloudflare_api_token = "api_token_here"
2+
cloudflare_zone_id = "zone_id_here"
3+
cloudflare_account_id = "account_id_here"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Variables
2+
variable "cloudflare_api_token" {
3+
description = "Cloudflare API Token"
4+
type = string
5+
sensitive = true
6+
}
7+
8+
variable "cloudflare_account_id" {
9+
description = "Cloudflare Account ID"
10+
type = string
11+
}
12+
13+
variable "cloudflare_zone_id" {
14+
description = "Cloudflare Zone ID"
15+
type = string
16+
}

0 commit comments

Comments
 (0)