From 9929e6b3c6623a8c186effd0959e7540ecdd64df Mon Sep 17 00:00:00 2001 From: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com> Date: Sat, 2 Sep 2023 00:10:09 +0530 Subject: [PATCH] feat(terraform): add edgedns for prd oldeworld (#590) --- .../prd-cluster-oldeworld/.terraform.lock.hcl | 22 +++++++++++++ terraform/prd-cluster-oldeworld/main.tf | 6 +++- .../prd-cluster-oldeworld/next-01-pxy.tf | 33 +++++++++++++++++++ .../next-02-pxy-origins.tf | 9 +++++ .../prd-cluster-oldeworld/next-03-clt.tf | 33 +++++++++++++++++++ .../prd-cluster-oldeworld/next-04-api.tf | 33 +++++++++++++++++++ .../prd-cluster-oldeworld/next-05-nws.tf | 33 +++++++++++++++++++ terraform/prd-cluster-oldeworld/providers.tf | 5 +++ terraform/prd-cluster-oldeworld/versions.tf | 5 +++ 9 files changed, 178 insertions(+), 1 deletion(-) diff --git a/terraform/prd-cluster-oldeworld/.terraform.lock.hcl b/terraform/prd-cluster-oldeworld/.terraform.lock.hcl index 009316f1..fd09e3f4 100644 --- a/terraform/prd-cluster-oldeworld/.terraform.lock.hcl +++ b/terraform/prd-cluster-oldeworld/.terraform.lock.hcl @@ -1,6 +1,28 @@ # This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. +provider "registry.terraform.io/akamai/akamai" { + version = "5.2.0" + constraints = "5.2.0" + hashes = [ + "h1:lQUyWvLu9vp7ud7vT3USriQRigpaCB0Xpvsossh5iS8=", + "zh:055ea62de79f9e38b7b09d242a16a98b038056dab84118632dc9c0fc0473aab8", + "zh:11a740846dcf460addb90ed1810d932b9be459e765ab993c01bd29ef01e7b1b3", + "zh:3af4bd8e91135bd0b49f9267d4d31334de99480b9d69fde0a252e7e2c79264da", + "zh:4796ef159a46f547d38b50c230de532009190f97b2dadb75525b1ceedcd7f4bf", + "zh:5555f2a712caf3fd7565ae167b5c3d51b12cc6ef565b08d1e09f675dc6191bb8", + "zh:55a35537a79ec46fc3259e2c5181901a1b59d41531bd86fb544d9f2e093634df", + "zh:6e48b3a321bedf7c3592bddea157a1d4ce4bfc15f557512b3ce0fed3a4c8e8d2", + "zh:8e16c641227243cd112fe7e9f1a750c7318d0fb11d7f6ebcd268593f44c0cfe7", + "zh:9c6e23d1c2fd3cbec17256e33db59e229f0c2be2ac8860dbb50501d09d703317", + "zh:9dc835200345ab09806b63fde0b2e0ad95db5a13a8a10380e4882bfe47f13cfd", + "zh:c495e6403f81845ba0e54422f580db8cc52e401f5db44112e034bb4404e21aa1", + "zh:e6bc54100260d83c7070fb7326447421828eb1e6d999ced0cbbe9e7198e58afc", + "zh:e6c490e8b6a6b91a4124a4bd26c027d3a3f2b0a25af2a870c65d3f35f4cda1b9", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} + provider "registry.terraform.io/hashicorp/hcp" { version = "0.69.0" constraints = "0.69.0" diff --git a/terraform/prd-cluster-oldeworld/main.tf b/terraform/prd-cluster-oldeworld/main.tf index db16e693..4e41015d 100644 --- a/terraform/prd-cluster-oldeworld/main.tf +++ b/terraform/prd-cluster-oldeworld/main.tf @@ -1,3 +1,7 @@ +locals { + zone = "freecodecamp.net" +} + # This data source depends on the stackscript resource # which is created in terraform/ops-stackscripts/main.tf data "linode_stackscripts" "cloudinit_scripts" { @@ -14,7 +18,7 @@ data "linode_stackscripts" "cloudinit_scripts" { # This data source depends on the domain resource # which is created in terraform/ops-dns/main.tf data "linode_domain" "ops_dns_domain" { - domain = "freecodecamp.net" + domain = local.zone } data "hcp_packer_image" "linode_ubuntu" { diff --git a/terraform/prd-cluster-oldeworld/next-01-pxy.tf b/terraform/prd-cluster-oldeworld/next-01-pxy.tf index 212d9d8d..1a19b3b5 100644 --- a/terraform/prd-cluster-oldeworld/next-01-pxy.tf +++ b/terraform/prd-cluster-oldeworld/next-01-pxy.tf @@ -124,3 +124,36 @@ resource "linode_domain_record" "prd_oldeworld_pxy_dnsrecord__private" { target = linode_instance.prd_oldeworld_pxy[count.index].private_ip_address ttl_sec = 120 } + +resource "akamai_dns_record" "prd_oldeworld_pxy_dnsrecord__vlan" { + count = local.pxy_node_count + + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "pxy-${count.index + 1}.oldeworld.prd.${local.zone}" + target = [trimsuffix(linode_instance_config.prd_oldeworld_pxy_config[count.index].interface[1].ipam_address, "/24")] +} + +resource "akamai_dns_record" "prd_oldeworld_pxy_dnsrecord__public" { + count = local.pxy_node_count + + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "pub.pxy-${count.index + 1}.oldeworld.prd.${var.network_subdomain}.${local.zone}" + target = [linode_instance.prd_oldeworld_pxy[count.index].ip_address] +} + +resource "akamai_dns_record" "prd_oldeworld_pxy_dnsrecord__private" { + count = local.pxy_node_count + + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "prv.pxy-${count.index + 1}.oldeworld.prd.${local.zone}" + target = [linode_instance.prd_oldeworld_pxy[count.index].private_ip_address] +} diff --git a/terraform/prd-cluster-oldeworld/next-02-pxy-origins.tf b/terraform/prd-cluster-oldeworld/next-02-pxy-origins.tf index 89da5dc6..b3d8b3fd 100644 --- a/terraform/prd-cluster-oldeworld/next-02-pxy-origins.tf +++ b/terraform/prd-cluster-oldeworld/next-02-pxy-origins.tf @@ -37,3 +37,12 @@ resource "linode_domain_record" "prd_oldeworld_nb_pxy_dnsrecord__public" { target = data.linode_nodebalancer.prd_oldeworld_nb_pxy.ipv4 ttl_sec = 120 } + +resource "akamai_dns_record" "prd_oldeworld_nb_pxy_dnsrecord__public" { + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "oldeworld.prd.${var.network_subdomain}.${local.zone}" + target = [data.linode_nodebalancer.prd_oldeworld_nb_pxy.ipv4] +} diff --git a/terraform/prd-cluster-oldeworld/next-03-clt.tf b/terraform/prd-cluster-oldeworld/next-03-clt.tf index 5198c5bf..025138b5 100644 --- a/terraform/prd-cluster-oldeworld/next-03-clt.tf +++ b/terraform/prd-cluster-oldeworld/next-03-clt.tf @@ -124,3 +124,36 @@ resource "linode_domain_record" "prd_oldeworld_clt_dnsrecord__private" { target = linode_instance.prd_oldeworld_clt[each.key].private_ip_address ttl_sec = 120 } + +resource "akamai_dns_record" "prd_oldeworld_clt_dnsrecord__vlan" { + for_each = { for i in local.clt_instances : i.instance => i } + + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "clt-${each.value.instance}.oldeworld.prd.${local.zone}" + target = [trimsuffix(linode_instance_config.prd_oldeworld_clt_config[each.key].interface[1].ipam_address, "/24")] +} + +resource "akamai_dns_record" "prd_oldeworld_clt_dnsrecord__public" { + for_each = { for i in local.clt_instances : i.instance => i } + + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "pub.clt-${each.value.instance}.oldeworld.prd.${var.network_subdomain}.${local.zone}" + target = [linode_instance.prd_oldeworld_clt[each.key].ip_address] +} + +resource "akamai_dns_record" "prd_oldeworld_clt_dnsrecord__private" { + for_each = { for i in local.clt_instances : i.instance => i } + + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "prv.clt-${each.value.instance}.oldeworld.prd.${local.zone}" + target = [linode_instance.prd_oldeworld_clt[each.key].private_ip_address] +} diff --git a/terraform/prd-cluster-oldeworld/next-04-api.tf b/terraform/prd-cluster-oldeworld/next-04-api.tf index 031fc586..ba4651fd 100644 --- a/terraform/prd-cluster-oldeworld/next-04-api.tf +++ b/terraform/prd-cluster-oldeworld/next-04-api.tf @@ -124,3 +124,36 @@ resource "linode_domain_record" "prd_oldeworld_api_dnsrecord__private" { target = linode_instance.prd_oldeworld_api[count.index].private_ip_address ttl_sec = 120 } + +resource "akamai_dns_record" "prd_oldeworld_api_dnsrecord__vlan" { + count = local.api_node_count + + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "api-${count.index + 1}.oldeworld.prd.${local.zone}" + target = [trimsuffix(linode_instance_config.prd_oldeworld_api_config[count.index].interface[1].ipam_address, "/24")] +} + +resource "akamai_dns_record" "prd_oldeworld_api_dnsrecord__public" { + count = local.api_node_count + + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "pub.api-${count.index + 1}.oldeworld.prd.${var.network_subdomain}.${local.zone}" + target = [linode_instance.prd_oldeworld_api[count.index].ip_address] +} + +resource "akamai_dns_record" "prd_oldeworld_api_dnsrecord__private" { + count = local.api_node_count + + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "prv.api-${count.index + 1}.oldeworld.prd.${local.zone}" + target = [linode_instance.prd_oldeworld_api[count.index].private_ip_address] +} diff --git a/terraform/prd-cluster-oldeworld/next-05-nws.tf b/terraform/prd-cluster-oldeworld/next-05-nws.tf index ceff84f4..dfad2924 100644 --- a/terraform/prd-cluster-oldeworld/next-05-nws.tf +++ b/terraform/prd-cluster-oldeworld/next-05-nws.tf @@ -134,3 +134,36 @@ resource "linode_domain_record" "prd_oldeworld_nws_dnsrecord__private" { target = linode_instance.prd_oldeworld_nws[each.key].private_ip_address ttl_sec = 120 } + +resource "akamai_dns_record" "prd_oldeworld_nws_dnsrecord__vlan" { + for_each = local.nws_instances + + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "nws-${each.value.name}.oldeworld.prd.${local.zone}" + target = [trimsuffix(linode_instance_config.prd_oldeworld_nws_config[each.key].interface[1].ipam_address, "/24")] +} + +resource "akamai_dns_record" "prd_oldeworld_nws_dnsrecord__public" { + for_each = local.nws_instances + + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "pub.nws-${each.value.name}.oldeworld.prd.${var.network_subdomain}.${local.zone}" + target = [linode_instance.prd_oldeworld_nws[each.key].ip_address] +} + +resource "akamai_dns_record" "prd_oldeworld_nws_dnsrecord__private" { + for_each = local.nws_instances + + zone = local.zone + recordtype = "A" + ttl = 120 + + name = "prv.nws-${each.value.name}.oldeworld.prd.${local.zone}" + target = [linode_instance.prd_oldeworld_nws[each.key].private_ip_address] +} diff --git a/terraform/prd-cluster-oldeworld/providers.tf b/terraform/prd-cluster-oldeworld/providers.tf index 49bb6bd6..451284d4 100644 --- a/terraform/prd-cluster-oldeworld/providers.tf +++ b/terraform/prd-cluster-oldeworld/providers.tf @@ -6,3 +6,8 @@ provider "hcp" { client_id = var.hcp_client_id client_secret = var.hcp_client_secret } + +provider "akamai" { + edgerc = ".edgerc" + config_section = "default" +} diff --git a/terraform/prd-cluster-oldeworld/versions.tf b/terraform/prd-cluster-oldeworld/versions.tf index 642dd8e2..6f53d290 100644 --- a/terraform/prd-cluster-oldeworld/versions.tf +++ b/terraform/prd-cluster-oldeworld/versions.tf @@ -9,6 +9,11 @@ terraform { source = "hashicorp/hcp" version = "0.69.0" } + + akamai = { + source = "akamai/akamai" + version = "5.2.0" + } } required_version = ">= 1" }