Current Terraform Version
Terraform v0.12.3
+ provider.aws v2.18.0
Use-case
Populate route53 records for a reverse DNS zone
I have an external data source which accepts one or more subnet CIDR’s and returns json data as a map of reverse DNS zone name and the ip-addresses associated to the zone
The data
{"0.0.10.in-addr.arpa" = ["16,10.0.0.16,0", "17,10.0.0.17,1",]}
With the example data I have, I am able to create route53 zones but I am stumped as to how to setup count, name, records and zone_id values for the route53 records.
Attempted Solution
locals {
reverse_zone_data = {"0.0.10.in-addr.arpa" = ["16,10.0.0.16,0", "17,10.0.0.17,1",]}
}
output "reverse_zone_record_count" {
value = [for zone in local.reverse_zone_data:
zone
]
}
resource "aws_route53_zone" "reverse_zone" {
count = length(keys(local.reverse_zone_data))
name = keys(local.reverse_zone_data)[count.index]
}
resource "aws_route53_record" "reverse_zone_record" {
count = length(local.reverse_zone_data[aws_route53_zone.reverse_zone[count.index].name])
name = ?
type = "PTR"
records = [?]
zone_id = aws_route53_zone.reverse_zone.*.id
ttl = 300
depends_on = [aws_route53_zone.reverse_zone]
}
Based on the data I have, I should be able to create 1 route53 zones and 2 records in the zone. Any pointers welcome.
The name for the zone record will be obtained from the 1st element of the comma separated item. e.g. 16,10.0.0.16,0
and the record part will be obtained from the 3rd element from the same data to be concatenated with a FQDN.