|
| 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 | +} |
0 commit comments