Hello, I am trying to use an if statement within a for_each in a module with values passed down but it keep ignoring the if statement and trying to apply the values to all.
My code block is;
resource "azurerm_subnet" "this" {
for_each = { for subnet in var.virtual_network_settings.subnets : subnet.name => subnet }
name = each.value["name"]
resource_group_name = var.resource_group_name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = [each.value["cidr_block"]]
service_endpoints = each.value["service_endpoints"]
enforce_private_link_endpoint_network_policies = each.value["enforce_private_link_endpoint_network_policies"]
enforce_private_link_service_network_policies = each.value["enforce_private_link_service_network_policies"]
dynamic "delegation" {
for_each = [for subnet in var.virtual_network_settings.subnets : subnet
if subnet.delegation_name != "null"
]
content {
name = delegation.value.delegation_name
service_delegation {
name = delegation.value.service_delegation_name
}
}
}
}
What am I missing here