|
| 1 | +terraform { |
| 2 | + required_version = ">= 1.12" |
| 3 | + required_providers { |
| 4 | + aws = { |
| 5 | + source = "hashicorp/aws" |
| 6 | + version = "~> 6.0" |
| 7 | + } |
| 8 | + cloudinit = { |
| 9 | + source = "hashicorp/cloudinit" |
| 10 | + version = "~> 2.0" |
| 11 | + } |
| 12 | + cloudflare = { |
| 13 | + source = "cloudflare/cloudflare" |
| 14 | + version = "~> 5.0" |
| 15 | + } |
| 16 | + sops = { |
| 17 | + source = "carlpett/sops" |
| 18 | + version = "~> 1.3" |
| 19 | + } |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +variable "cloudflare_wcf_api_token" { |
| 24 | + type = string |
| 25 | + sensitive = true |
| 26 | + ephemeral = true |
| 27 | +} |
| 28 | + |
| 29 | +locals { |
| 30 | + aws_tags = { |
| 31 | + Application = "wcn" |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +provider "aws" { |
| 36 | + region = "eu-central-1" |
| 37 | + default_tags { |
| 38 | + tags = local.aws_tags |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +provider "aws" { |
| 43 | + region = "eu-central-1" |
| 44 | + alias = "eu" |
| 45 | + default_tags { |
| 46 | + tags = local.aws_tags |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +provider "aws" { |
| 51 | + region = "us-east-1" |
| 52 | + alias = "us" |
| 53 | + default_tags { |
| 54 | + tags = local.aws_tags |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +provider "aws" { |
| 59 | + region = "ap-southeast-1" |
| 60 | + alias = "ap" |
| 61 | + default_tags { |
| 62 | + tags = local.aws_tags |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +provider "aws" { |
| 67 | + region = "sa-east-1" |
| 68 | + alias = "sa" |
| 69 | + default_tags { |
| 70 | + tags = local.aws_tags |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +provider "cloudflare" { |
| 75 | + api_token = var.cloudflare_wcf_api_token |
| 76 | +} |
| 77 | + |
| 78 | +provider "sops" {} |
| 79 | + |
| 80 | +module "sops-encryption-key" { |
| 81 | + source = "../modules/sops-encryption-key" |
| 82 | +} |
| 83 | + |
| 84 | +resource "aws_route53_zone" "this" { |
| 85 | + name = "mainnet.walletconnect.network" |
| 86 | +} |
| 87 | + |
| 88 | +resource "cloudflare_dns_record" "ns_delegation" { |
| 89 | + count = 4 |
| 90 | + zone_id = local.cloudflare_zone_id |
| 91 | + name = aws_route53_zone.this.name |
| 92 | + content = aws_route53_zone.this.name_servers[count.index] |
| 93 | + type = "NS" |
| 94 | + ttl = 1 |
| 95 | +} |
| 96 | + |
| 97 | +locals { |
| 98 | + cloudflare_zone_id = "a97af2cd2fd2da7a93413e455ed47f2c" |
| 99 | + |
| 100 | + db_config = { |
| 101 | + image = "ghcr.io/walletconnect/wcn-db:251113.0" |
| 102 | + cpu_arch = "x86" |
| 103 | + cpu_cores = 8 |
| 104 | + memory = 16 |
| 105 | + disk = 100 |
| 106 | + } |
| 107 | + |
| 108 | + node_config = { |
| 109 | + image = "ghcr.io/walletconnect/wcn-node:251113.0" |
| 110 | + cpu_cores = 4 |
| 111 | + memory = 8 |
| 112 | + } |
| 113 | + |
| 114 | + prometheus_config = { |
| 115 | + image = "docker.io/prom/prometheus:v3.7.3" |
| 116 | + cpu_burst = true |
| 117 | + cpu_cores = 2 |
| 118 | + memory = 8 |
| 119 | + disk = 50 |
| 120 | + } |
| 121 | + |
| 122 | + grafana_config = { |
| 123 | + image = "docker.io/grafana/grafana:12.3" |
| 124 | + cpu_burst = true |
| 125 | + cpu_cores = 2 |
| 126 | + memory = 4 |
| 127 | + disk = 5 |
| 128 | + |
| 129 | + prometheus_regions = ["eu", "us", "ap", "sa"] |
| 130 | + } |
| 131 | + |
| 132 | + relay_account_id = "780545098720" |
| 133 | + vpc_peering_connections = { |
| 134 | + "relay-eu-central-1" : { |
| 135 | + account_id = local.relay_account_id |
| 136 | + cidr = "10.11.0.0/16" |
| 137 | + } |
| 138 | + "relay-us-east-1" : { |
| 139 | + account_id = local.relay_account_id |
| 140 | + cidr = "10.12.0.0/16" |
| 141 | + } |
| 142 | + "relay-ap-southeast-1" : { |
| 143 | + account_id = local.relay_account_id |
| 144 | + cidr = "10.13.0.0/16" |
| 145 | + } |
| 146 | + "relay-sa-east-1" : { |
| 147 | + account_id = local.relay_account_id |
| 148 | + cidr = "10.14.0.0/16" |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + eu_operators = { |
| 153 | + wallet-connect = { |
| 154 | + vpc_cidr_octet = 5 # 10.5.0.0/16 |
| 155 | + vpc_peering_connections = local.vpc_peering_connections |
| 156 | + db = local.db_config |
| 157 | + nodes = [ |
| 158 | + local.node_config, |
| 159 | + local.node_config, |
| 160 | + ] |
| 161 | + prometheus = local.prometheus_config |
| 162 | + grafana = local.grafana_config |
| 163 | + route53_zone = aws_route53_zone.this |
| 164 | + } |
| 165 | + wallet-connect-2 = { |
| 166 | + vpc_cidr_octet = 0 # 10.0.0.0/16 |
| 167 | + db = local.db_config |
| 168 | + nodes = [ |
| 169 | + local.node_config, |
| 170 | + local.node_config, |
| 171 | + ] |
| 172 | + } |
| 173 | + wallet-connect-3 = { |
| 174 | + vpc_cidr_octet = 0 # 10.0.0.0/16 |
| 175 | + db = local.db_config |
| 176 | + nodes = [ |
| 177 | + local.node_config, |
| 178 | + local.node_config, |
| 179 | + ] |
| 180 | + } |
| 181 | + wallet-connect-4 = { |
| 182 | + vpc_cidr_octet = 0 # 10.0.0.0/16 |
| 183 | + db = local.db_config |
| 184 | + nodes = [ |
| 185 | + local.node_config, |
| 186 | + local.node_config, |
| 187 | + ] |
| 188 | + } |
| 189 | + wallet-connect-5 = { |
| 190 | + vpc_cidr_octet = 0 # 10.0.0.0/16 |
| 191 | + db = local.db_config |
| 192 | + nodes = [ |
| 193 | + local.node_config, |
| 194 | + local.node_config, |
| 195 | + ] |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + us_operators = { |
| 200 | + wallet-connect = { |
| 201 | + vpc_cidr_octet = 6 # 10.6.0.0/16 |
| 202 | + vpc_peering_connections = local.vpc_peering_connections |
| 203 | + db = local.db_config |
| 204 | + nodes = [ |
| 205 | + local.node_config, |
| 206 | + local.node_config, |
| 207 | + ] |
| 208 | + prometheus = local.prometheus_config |
| 209 | + route53_zone = aws_route53_zone.this |
| 210 | + } |
| 211 | + } |
| 212 | + |
| 213 | + ap_operators = { |
| 214 | + wallet-connect = { |
| 215 | + vpc_cidr_octet = 7 # 10.7.0.0/16 |
| 216 | + vpc_peering_connections = local.vpc_peering_connections |
| 217 | + db = local.db_config |
| 218 | + nodes = [ |
| 219 | + local.node_config, |
| 220 | + local.node_config, |
| 221 | + ] |
| 222 | + prometheus = local.prometheus_config |
| 223 | + route53_zone = aws_route53_zone.this |
| 224 | + } |
| 225 | + } |
| 226 | + |
| 227 | + sa_operators = { |
| 228 | + wallet-connect = { |
| 229 | + vpc_cidr_octet = 8 # 10.8.0.0/16 |
| 230 | + vpc_peering_connections = local.vpc_peering_connections |
| 231 | + db = local.db_config |
| 232 | + nodes = [ |
| 233 | + local.node_config, |
| 234 | + local.node_config, |
| 235 | + ] |
| 236 | + prometheus = local.prometheus_config |
| 237 | + route53_zone = aws_route53_zone.this |
| 238 | + } |
| 239 | + } |
| 240 | +} |
| 241 | + |
| 242 | +module "eu-central-1" { |
| 243 | + source = "../modules/node-operator" |
| 244 | + for_each = local.eu_operators |
| 245 | + |
| 246 | + config = merge(each.value, { |
| 247 | + name = each.key |
| 248 | + sops_file_path = "${path.module}/sops/eu.${each.key}.json" |
| 249 | + }) |
| 250 | + |
| 251 | + providers = { |
| 252 | + aws = aws.eu |
| 253 | + } |
| 254 | +} |
| 255 | + |
| 256 | +module "us-east-1" { |
| 257 | + source = "../modules/node-operator" |
| 258 | + for_each = local.us_operators |
| 259 | + |
| 260 | + config = merge(each.value, { |
| 261 | + name = each.key |
| 262 | + sops_file_path = "${path.module}/sops/us.${each.key}.json" |
| 263 | + }) |
| 264 | + |
| 265 | + providers = { |
| 266 | + aws = aws.us |
| 267 | + } |
| 268 | +} |
| 269 | + |
| 270 | +module "ap-southeast-1" { |
| 271 | + source = "../modules/node-operator" |
| 272 | + for_each = local.ap_operators |
| 273 | + |
| 274 | + config = merge(each.value, { |
| 275 | + name = each.key |
| 276 | + sops_file_path = "${path.module}/sops/ap.${each.key}.json" |
| 277 | + }) |
| 278 | + |
| 279 | + providers = { |
| 280 | + aws = aws.ap |
| 281 | + } |
| 282 | +} |
| 283 | + |
| 284 | +module "sa-east-1" { |
| 285 | + source = "../modules/node-operator" |
| 286 | + for_each = local.sa_operators |
| 287 | + |
| 288 | + config = merge(each.value, { |
| 289 | + name = each.key |
| 290 | + sops_file_path = "${path.module}/sops/sa.${each.key}.json" |
| 291 | + }) |
| 292 | + |
| 293 | + providers = { |
| 294 | + aws = aws.sa |
| 295 | + } |
| 296 | +} |
| 297 | + |
| 298 | +output "sops-encryption-key-arn" { |
| 299 | + value = module.sops-encryption-key.arn |
| 300 | +} |
0 commit comments