From 472083eec5ba6283d461ccbaeea3854581abc7a5 Mon Sep 17 00:00:00 2001 From: Rustie Lin Date: Wed, 17 May 2023 15:11:36 -0700 Subject: [PATCH] [tf/gcp] add dns support for GCP testnet --- terraform/aptos-node-testnet/gcp/main.tf | 3 +++ terraform/aptos-node/aws/dns.tf | 2 ++ terraform/aptos-node/gcp/dns.tf | 18 ++++++++++-------- terraform/aptos-node/gcp/variables.tf | 5 +++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/terraform/aptos-node-testnet/gcp/main.tf b/terraform/aptos-node-testnet/gcp/main.tf index 8573f2e8f31f7..3a512ca20dfc3 100644 --- a/terraform/aptos-node-testnet/gcp/main.tf +++ b/terraform/aptos-node-testnet/gcp/main.tf @@ -29,6 +29,9 @@ module "validator" { zone_name = var.zone_name # keep empty if you don't want a DNS name zone_project = var.zone_project record_name = var.record_name + # do not create the main fullnode and validator DNS records + # instead, rely on external-dns from the testnet-addons + create_dns_records = false # General chain config era = var.era diff --git a/terraform/aptos-node/aws/dns.tf b/terraform/aptos-node/aws/dns.tf index 31b00a381ca1c..8c4d93fe9dba3 100644 --- a/terraform/aptos-node/aws/dns.tf +++ b/terraform/aptos-node/aws/dns.tf @@ -24,6 +24,7 @@ locals { data "kubernetes_service" "validator-lb" { count = var.zone_id == "" || !var.create_records ? 0 : 1 metadata { + # This is the main validator LB service that is created by the aptos-node helm chart name = "${local.workspace_name}-aptos-node-0-validator-lb" } depends_on = [time_sleep.lb_creation] @@ -32,6 +33,7 @@ data "kubernetes_service" "validator-lb" { data "kubernetes_service" "fullnode-lb" { count = var.zone_id == "" || !var.create_records ? 0 : 1 metadata { + # This is the main fullnode LB service that is created by the aptos-node helm chart name = "${local.workspace_name}-aptos-node-0-fullnode-lb" } depends_on = [time_sleep.lb_creation] diff --git a/terraform/aptos-node/gcp/dns.tf b/terraform/aptos-node/gcp/dns.tf index 705d5fa4867d5..9cc8286e5239b 100644 --- a/terraform/aptos-node/gcp/dns.tf +++ b/terraform/aptos-node/gcp/dns.tf @@ -14,17 +14,19 @@ locals { } data "kubernetes_service" "validator-lb" { - count = var.zone_name != "" ? 1 : 0 + count = var.zone_name != "" && var.create_dns_records ? 1 : 0 metadata { - name = "${local.workspace_name}-aptos-node-validator-lb" + # This is the main validator LB service that is created by the aptos-node helm chart + name = "${local.workspace_name}-aptos-node-0-validator-lb" } depends_on = [time_sleep.lb_creation] } data "kubernetes_service" "fullnode-lb" { - count = var.zone_name != "" ? 1 : 0 + count = var.zone_name != "" && var.create_dns_records ? 1 : 0 metadata { - name = "${local.workspace_name}-aptos-node-fullnode-lb" + # This is the main fullnode LB service that is created by the aptos-node helm chart + name = "${local.workspace_name}-aptos-node-0-fullnode-lb" } depends_on = [time_sleep.lb_creation] } @@ -36,7 +38,7 @@ data "google_dns_managed_zone" "aptos" { } resource "google_dns_record_set" "validator" { - count = var.zone_name != "" ? 1 : 0 + count = var.zone_name != "" && var.create_dns_records ? 1 : 0 managed_zone = data.google_dns_managed_zone.aptos[0].name project = data.google_dns_managed_zone.aptos[0].project name = "${random_string.validator-dns.result}.${local.record_name}.${data.google_dns_managed_zone.aptos[0].dns_name}" @@ -46,7 +48,7 @@ resource "google_dns_record_set" "validator" { } resource "google_dns_record_set" "fullnode" { - count = var.zone_name != "" ? 1 : 0 + count = var.zone_name != "" && var.create_dns_records ? 1 : 0 managed_zone = data.google_dns_managed_zone.aptos[0].name project = data.google_dns_managed_zone.aptos[0].project name = "${local.record_name}.${data.google_dns_managed_zone.aptos[0].dns_name}" @@ -56,9 +58,9 @@ resource "google_dns_record_set" "fullnode" { } output "validator_endpoint" { - value = var.zone_name != "" ? "/dns4/${trimsuffix(google_dns_record_set.validator[0].name, ".")}/tcp/${data.kubernetes_service.validator-lb[0].spec[0].port[0].port}" : null + value = var.zone_name != "" && var.create_dns_records ? "/dns4/${trimsuffix(google_dns_record_set.validator[0].name, ".")}/tcp/${data.kubernetes_service.validator-lb[0].spec[0].port[0].port}" : null } output "fullnode_endpoint" { - value = var.zone_name != "" ? "/dns4/${trimsuffix(google_dns_record_set.fullnode[0].name, ".")}/tcp/${data.kubernetes_service.fullnode-lb[0].spec[0].port[0].port}" : null + value = var.zone_name != "" && var.create_dns_records ? "/dns4/${trimsuffix(google_dns_record_set.fullnode[0].name, ".")}/tcp/${data.kubernetes_service.fullnode-lb[0].spec[0].port[0].port}" : null } diff --git a/terraform/aptos-node/gcp/variables.tf b/terraform/aptos-node/gcp/variables.tf index f51d30c9a390b..81f73c42d1510 100644 --- a/terraform/aptos-node/gcp/variables.tf +++ b/terraform/aptos-node/gcp/variables.tf @@ -61,6 +61,11 @@ variable "record_name" { default = ".aptos" } +variable "create_dns_records" { + description = "Creates DNS records in var.zone_name that point to k8s service, as opposed to using external-dns or other means" + default = true +} + variable "helm_chart" { description = "Path to aptos-validator Helm chart file" default = ""