Conditionals in terraform are proving to be a thorn for me. I know that the following is not valid but it demonstrates what I’m trying to do (compare two maps and merge if they have a matching tag).
route_table_subnet_map = {
for route_table in aws_route_table.private : [
for subnet in aws_subnet.private : {
if subnet.tags["env"] == route_table.tags["env"] : <---BROKEN
merge(subnet, {route_table_id = route_table.id})
}
]
}
}
Edit: This is probably closer to right but still not functional
for route_table in aws_route_table.private : [
for subnet in aws_subnet.private : {
merge(subnet, {route_table_id = route_table.id} ? subnet.tags["env"] == route_table.tags["env"] : false)
}
]
}
Please and thank you.