Skip to content

Commit

Permalink
Fix aws_route53_zone setup
Browse files Browse the repository at this point in the history
* one(try(...),...) didn't work -> use a simple ternary operator as everywhere else in this module
* output local.nameservers directly (type is list of strings, should be ok for consumers)
* delete aws_route53_record.dns resource (if there is a parent zone, it should already have a "NS" record)
  • Loading branch information
jochenehret authored and rkoster committed Jun 1, 2023
1 parent 370523f commit 9ad8add
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions terraform/aws/templates/cf_dns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ data "aws_route53_zone" "parent" {
}

output "env_dns_zone_name_servers" {
value = ["${split(",", local.name_servers)}"]
value = local.name_servers
}

locals {
zone_id = one(try(aws_route53_zone.env_dns_zone[*].zone_id, data.aws_route53_zone.parent[*].zone_id))
name_servers = join(",", flatten(concat(try(aws_route53_zone.env_dns_zone[*].name_servers, data.aws_route53_zone.parent[*].name_servers), tolist([tolist([""])]))))
zone_id = var.parent_zone == "" ? aws_route53_zone.env_dns_zone[0].zone_id : data.aws_route53_zone.parent[0].zone_id
name_servers = var.parent_zone == "" ? aws_route53_zone.env_dns_zone[0].name_servers : data.aws_route53_zone.parent[0].name_servers
}

resource "aws_route53_zone" "env_dns_zone" {
Expand All @@ -33,17 +33,6 @@ resource "aws_route53_zone" "env_dns_zone" {
}
}

resource "aws_route53_record" "dns" {
count = "${var.parent_zone == "" ? 1 : 0}"

zone_id = "${local.zone_id}"
name = "${var.system_domain}"
type = "NS"
ttl = 300

records = ["${local.name_servers}"]
}

resource "aws_route53_record" "wildcard_dns" {
zone_id = "${local.zone_id}"
name = "*.${var.system_domain}"
Expand Down

0 comments on commit 9ad8add

Please sign in to comment.