Skip to content

Commit

Permalink
changes to local calcs for zones and vnets
Browse files Browse the repository at this point in the history
  • Loading branch information
jtracey93 committed May 28, 2024
1 parent 48d679b commit f0f6720
Showing 1 changed file with 51 additions and 9 deletions.
60 changes: 51 additions & 9 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,56 @@ locals {
"swedensouth" : "sds"
}

private_link_private_dns_zones_replaced_regionName = toset([for zone in var.private_link_private_dns_zones : replace(zone["zone_name"], "{regionName}", local.location_short_name)])
private_link_private_dns_zones_replaced_regionCode = toset([for zone in local.private_link_private_dns_zones_replaced_regionName : replace(zone, "{regionCode}", local.azure_region_geo_codes_short_name_as_key[local.location_short_name])])
private_link_private_dns_zones_replaced_regionName_map = { for k, v in var.private_link_private_dns_zones : k => {
zone_name = replace(v.zone_name, "{regionName}", local.location_short_name)
} }

private_link_private_dns_zones_replaced_regionCode_map = { for k, v in local.private_link_private_dns_zones_replaced_regionName_map : k => {
zone_name = replace(v.zone_name, "{regionCode}", local.azure_region_geo_codes_short_name_as_key[local.location_short_name])
} }

# Use a DIY approach

combined_private_link_private_dns_zones_replaced_with_vnets_to_link = {
for item in flatten([
for zone_key, zone_value in local.private_link_private_dns_zones_replaced_regionCode_map : [
for vnet_key, vnet_value in var.virtual_network_resource_ids_to_link_to : {
zone_key = zone_key
zone_value = zone_value
vnet_key = vnet_key
vnet_value = vnet_value
}
]
]
) : "${item.zone_key}/${item.vnet_key}" => item
}


#########

# Use setproduct()

set_of_private_link_private_dns_zones_replaced_regionCode = [
for k, v in local.private_link_private_dns_zones_replaced_regionCode_map : {
key = k
zone_name = v.zone_name
}
]

set_of_virtual_network_resource_ids_to_link_to = [
for k, v in var.virtual_network_resource_ids_to_link_to : {
key = k
vnet_resource_id = v.vnet_resource_id
}
]

product_of_private_link_private_dns_zones_replaced_combined_with_vnets_to_link = [
for pair in setproduct(local.set_of_private_link_private_dns_zones_replaced_regionCode, local.set_of_virtual_network_resource_ids_to_link_to) : {
zone_key = pair[0].key
zone_value = pair[0].zone_name
vnet_key = pair[1].key
vnet_value = pair[1].vnet_resource_id
}
]

# flattened_map_of_private_link_private_dns_zones_with_vnet_links = {
# for item in flatten(
# [
# for zone in local.private_link_private_dns_zones_replaced_regionCode
# ]
# )
# }
}

0 comments on commit f0f6720

Please sign in to comment.