I am trying to set up my DNS zones and records with in those zones and I can't get the structured collection I am looking for to pass into the tf file that will generate all the zones and records. I have a list of DNS objects and each object will have multiple lists of record objects. I am trying to create lists of just records (a, cname, txt, ...). Im trying merges and flattening and I just not sure how to get what I need. I keep trying different patterns with merge and flatten but keep getting errors in different configurations.
Errors:
Error: Invalid 'for' expression. Extra characters after the end of the 'for' expression.
Error: Missing attribute value. Expected an attribute value, introduced by an equals sign ("=").
Error: Invalid 'for' expression. Key expression is required when building an object.
Error: Missing key/value separator. Expected an equals sign ("=") to mark the beginning of the attribute value.
Variable Definition:
variable "dns_target_child_zones" {
type = list(object({
name = string
a_records = list(object({
name = string
ttl = number
ip_address = string
}))
cname_records = list(object({
name = string
ttl = number
record = string
}))
mx_records = list(object({
name = string
ttl = number
record = list(object({
preference = number
exchange = string
}))
}))
txt_records = list(object({
name = string
ttl = number
record = list(object({
value = string
}))
}))
}))
}
Locals file:
locals {
a_records = flatten ([
])
cname_records = flatten ([
])
mx_records = flatten ([
])
txt_records = flatten ([
])
}
The output structure I am trying to produce so I can do something like count = length(locals.a_records)
[
{
name =
zone_name =
ttl =
records =
},
{
name =
zone_name =
ttl =
records =
}
...
]