Skip to content

Commit

Permalink
Allow customizing the DNS project for GCP
Browse files Browse the repository at this point in the history
  • Loading branch information
nacx committed Feb 10, 2023
1 parent 1ac7bb3 commit bf8b200
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion addons/external-dns/gcp/credentials/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data "terraform_remote_state" "infra" {
}

locals {
dns_project = endswith(var.tsb_fqdn, ".gcp.cx.tetrate.info") ? "dns-terraform-sandbox" : data.terraform_remote_state.infra.outputs.project_id
dns_project = coalesce(var.gcp_dns_project, endswith(var.tsb_fqdn, ".gcp.cx.tetrate.info") ? "dns-terraform-sandbox" : data.terraform_remote_state.infra.outputs.project_id)
}

resource "google_service_account" "external_dns" {
Expand Down
4 changes: 4 additions & 0 deletions addons/external-dns/gcp/credentials/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ variable "tsb_mp" {
variable "gcp_k8s_regions" {
default = []
}

variable "gcp_dns_project" {
default = null
}
2 changes: 1 addition & 1 deletion addons/external-dns/gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ module "external_dns" {
dns_provider = "google"
tsb_fqdn = var.tsb_fqdn
dns_zone = replace(var.tsb_fqdn, "/^[^\\.]+\\./", "") # Remove the first part of the fqdn
google_project = data.terraform_remote_state.dns.outputs.dns_project
google_project = coalesce(var.gcp_dns_project, data.terraform_remote_state.dns.outputs.dns_project)
google_service_account_key = data.terraform_remote_state.dns.outputs.dns_credentials
}
4 changes: 4 additions & 0 deletions addons/external-dns/gcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ variable "tsb_fqdn" {
variable "gcp_k8s_regions" {
default = []
}

variable "gcp_dns_project" {
default = null
}
7 changes: 3 additions & 4 deletions modules/gcp/register_fqdn/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ resource "google_dns_record_set" "shared_fqdn" {

## Public DNS Zone

resource "google_dns_managed_zone" "public" {
data "google_dns_managed_zone" "public" {
count = local.public_zone ? 1 : 0
project = var.project_id
name = local.zone_name
dns_name = "${local.dns_name}."
name = local.zone_name
}

resource "google_dns_record_set" "public_fqdn" {
count = local.public_zone ? 1 : 0
project = var.project_id
managed_zone = google_dns_managed_zone.public[0].name
managed_zone = data.google_dns_managed_zone.public[0].name
name = "${var.fqdn}."
type = "A"
ttl = 300
Expand Down
2 changes: 1 addition & 1 deletion tsb/fqdn/gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ module "register_fqdn" {
dns_zone = var.dns_zone
fqdn = var.fqdn
address = var.address
project_id = data.terraform_remote_state.infra.outputs.project_id
project_id = coalesce(var.gcp_dns_project, data.terraform_remote_state.infra.outputs.project_id)
vpc_id = reverse(split("/", data.terraform_remote_state.infra.outputs.vpc_id))[0]
}
4 changes: 4 additions & 0 deletions tsb/fqdn/gcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ variable "tsb_mp" {
variable "gcp_k8s_regions" {
default = []
}

variable "gcp_dns_project" {
default = null
}

0 comments on commit bf8b200

Please sign in to comment.