Trying to loop through dns records but getting the error:
The given “for_each” argument value is unsuitable: the “for_each” argument must be a map, or set of strings, and you have provided a value of type tuple.
variable "dns_records" {
type = map(any)
default = {
"www" = {
"recordtype" = "A"
"recorddata" = "152.152.152.152"
}
"ftp" = {
"recordtype" = "CNAME"
"recorddata" = "www.ftp.org"
}
"mail" = {
"recordtype" = "TXT"
"recorddata" = "qwertyuiop"
}
}
}
locals {
nestedlist = flatten([
for n, x in var.dns_records : [
for t, v in x : {
name = n,
type = t,
value = v
}
]
])
}
resource "cloudflare_record" "dns_record" {
for_each = local.nestedlist
name = each.value.name
type = each.value.type
value = each.value.value
proxied = false
ttl = 1
zone_id = "asdfghjklzxcvbnm"
}