I want to be able to create multiple R53 records, using the following format defined in TF Vars:
custom_zone_records = {
"demo.a.com" = [
{"*.b" = {type: "CNAME", records: ["d.com"]}},
{"*.c" = {type: "CNAME", records: ["d.com"]}}
]
}
Using the record as an example, it should create the R53 record of:
Name: *.b.demo.a.com
Type: CNAME
Records: ["d.com"]
The input variable is defined as:
variable "custom_zone_records" {
description = "A map of maps for custom zone records"
type = map(list(map(object({
type = string
records: list(string)
}))))
}
I've tried mutating the array within the resource creation using a for_each and I've tried formatting using a locals file, with no success.
Is there a better way to format or handle this, other than having the array more explicit?
Thanks.
Edit:
If I were to not use the variable, I would have to write the following code (as an example of what I am trying to achieve)
resource "aws_route53_record" "demo_a" {
zone_id = "ZONE_ID"
name = "*.b.demo.a.com"
type = "CNAME"
records = ["d.com"]
ttl = 60
}
resource "aws_route53_record" "demo_a" {
zone_id = "ZONE_ID"
name = "*.c.demo.a.com"
type = "CNAME"
records = ["d.com"]
ttl = 60
}
for_each(which loop through the top level zone e.g.demo.a.com) then tried adding a look up, to loop through the values. Kind of stuck at that that point - how do we (if possible) loop through loops in resources, the question is realistically. - James Elliottflattencall so that you can then for_each over the unrolled local. - luk2302