How do I loop subnet nsg_associations

resource “azurerm_subnet” “subnet-dynamic” {
for_each = var.subnets_dynamic
name = each.value[“name”]
resource_group_name = azurerm_resource_group.resource_group1.name
virtual_network_name = azurerm_virtual_network.vnet1.name
address_prefixes = each.value[“address_prefixes”]
service_endpoints = [“Microsoft.Storage”]
}

What would be the best approach for attaching each of the subnets to an association for a loop from the above.

Any advice would be great. I just can’t quite work this out.

resource “azurerm_subnet_network_security_group_association” “nsg_association” {
subnet_id = >>
network_security_group_id = azurerm_network_security_group.nsg_standard.id
}

I think this looks fine resource “azurerm_subnet_network_security_group_association” “nsg_association_dyn” {
for_each = var.subnets_dynamic
subnet_id = azurerm_subnet.subnet-dynamic[each.key].id
network_security_group_id = azurerm_network_security_group.nsg_standard.id
}