Hello,
I have the following local structure.
locals {
warehouse_dbs_metadata = {
db1 = {
edition = "Standard",
performance_level = "S0",
firewall_rules = [
{ name = "test1", start_ip = "10.0.17.62", end_ip = "10.0.17.62" },
{ name = "test2", start_ip = "10.0.17.63", end_ip = "10.0.17.63" }
] },
db2 = {
edition = "Standard",
performance_level = "S0",
firewall_rules = [
{ name = "test3", start_ip = "10.0.17.62", end_ip = "10.0.17.62" },
{ name = "test4", start_ip = "10.0.17.63", end_ip = "10.0.17.63" }
] }
}
nestedforeach_p = flatten([
for w in keys(local.warehouse_dbs_metadata) : [
for v in values(local.warehouse_dbs_metadata) : [
for f in v.firewall_rules : [
{
key = w,
name = f.name,
start_ip = f.start_ip,
end_ip = f.end_ip
}
]
]
]
])
Output of nestedforeach_p
looks like:
test = [
{
"end_ip" = "10.0.17.62"
"key" = "db1"
"name" = "test1"
"start_ip" = "10.0.17.62"
},
{
"end_ip" = "10.0.17.63"
"key" = "db1"
"name" = "test2"
"start_ip" = "10.0.17.63"
},
{
"end_ip" = "10.0.17.62"
"key" = "db1"
"name" = "test3"
"start_ip" = "10.0.17.62"
},
{
"end_ip" = "10.0.17.63"
"key" = "db1"
"name" = "test4"
"start_ip" = "10.0.17.63"
},
{
"end_ip" = "10.0.17.62"
"key" = "db2"
"name" = "test1"
"start_ip" = "10.0.17.62"
},
{
"end_ip" = "10.0.17.63"
"key" = "db2"
"name" = "test2"
"start_ip" = "10.0.17.63"
},
{
"end_ip" = "10.0.17.62"
"key" = "db2"
"name" = "test3"
"start_ip" = "10.0.17.62"
},
{
"end_ip" = "10.0.17.63"
"key" = "db2"
"name" = "test4"
"start_ip" = "10.0.17.63"
},
]
My goal is to use this with for_each
withing a resource. However everything i have tried results in a terraform crash.
resource "null_resource" "resource" {
for_each = local.nestedforeach_p
triggers = {
key = each.key,
name = each.name,
start_ip = each.start_ip,
end_ip = each.end_ip
}
}
I am sure its something dumb, any help would be appreciated.