Empty values in an AWS Route 53 record

A regular DNS record is missing its required target values

Description

Set records to values appropriate for each non-alias Route 53 record. For an alias, specify its target and hosted zone in alias.

Potential impact

An empty record list can prevent the DNS change and leave clients unable to resolve the expected name.

Remediation

Reject empty module inputs and validate the values for the record type, such as A, CNAME or NS. For NS records, use the name servers authoritative for the record name.

Examples

The excerpts use aws_route53_zone.example for zone_id, and the second takes its name servers from that same zone. For child delegation, set zone_id to the parent zone ID and records to the child zone’s name servers. Check the existing NS record before applying with allow_overwrite enabled.

Before

hcl
resource "aws_route53_record" "service_record" {
  allow_overwrite = true
  name            = "test.example.com"
  ttl             = 30
  type            = "NS"
  zone_id         = aws_route53_zone.example.zone_id

  records = []
}

After

hcl
resource "aws_route53_record" "service_record" {
  allow_overwrite = true
  name            = "test.example.com"
  ttl             = 30
  type            = "NS"
  zone_id         = aws_route53_zone.example.zone_id

  records = [
    aws_route53_zone.example.name_servers[0],
    aws_route53_zone.example.name_servers[1],
    aws_route53_zone.example.name_servers[2],
    aws_route53_zone.example.name_servers[3],
  ]
}

References