Skip to content

Commit

Permalink
[tf/gcp] add dns support for GCP testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
rustielin committed May 17, 2023
1 parent 27b25e0 commit 472083e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions terraform/aptos-node-testnet/gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions terraform/aptos-node/aws/dns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
18 changes: 10 additions & 8 deletions terraform/aptos-node/gcp/dns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand All @@ -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}"
Expand All @@ -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}"
Expand All @@ -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
}
5 changes: 5 additions & 0 deletions terraform/aptos-node/gcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ variable "record_name" {
default = "<workspace>.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 = ""
Expand Down

0 comments on commit 472083e

Please sign in to comment.