I'm relatively new to Terraform and I'm looking to simplify some private r53 zones I need to create using for_each.
I have the following local which I want to use to create private zones and associated A records in those zones:
locals {
private_zones = [
{
name = "foo.com"
txt = [
"This is the txt record for foo.com"]
ttl = 300
records = {
"host1" = "192.168.0.1",
"host2" = "192.168.0.2"
}
},
{
name = "bar.com"
txt = [
"This is the txt record for bar.com"]
ttl = 300
records = {
"host1" = "192.168.0.3",
"host2" = "192.168.0.4"
}
}
]
}
I've found some code which will allow me to iterate over the local to create the zones
resource "aws_route53_zone" "zone" {
for_each = { for name in local.private_zones : name.name => name }
name = each.value.name
vpc {
vpc_id = <vpc_id>
}
}
but I've no idea how I can iterate and create A records in the respective zone using the records list in each local.