I have the following map of object:
external-dns = {
internal = {
create_iam_policy = true
...
}
external = {
create_iam_policy = false
}
}
I would like to be able to iterate over a ressource aws_iam_policy
with for_each based on the condition inside the map.
For example:
resource "aws_iam_policy" "external-dns" {
for_each = local.external-dns if each.values["create_iam"]
count = local.external-dns["enabled"] && local.external-dns["create_iam_resources_irsa"] ? 1 : 0
name = "tf-${var.cluster-name}-${local.external-dns["name"]}"
policy = local.external-dns["iam_policy_override"] = = "" ? data.aws_iam_policy_document.external-dns.json : local.external-dns["iam_policy_override"]
}
But only if each.value[“create_iam”] is true. I don’t know if it is at all possible and if it is I don’t know the correct syntax or function to use to create a sub map wth only the map that satisfy the condition.
Thanks