Hello!
Please see the following .tfvars file and resources.
resolver_config = {
primary = {
name = "resolver-we",
location = "westeurope",
vnetID = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/hub-rg/providers/Microsoft.Network/virtualNetworks/vnet1"
inboundSubnetId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/hub-rg/providers/Microsoft.Network/virtualNetworks/vnet1/subnets/dnsInboundSubnet",
outboundSubnetId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/hub-rg/providers/Microsoft.Network/virtualNetworks/vnet1/subnets/dnsOutboundSubnet"
},
secondary = {
name = "resolver-sc",
location = "swedencentral",
vnetID = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/hub-rg/providers/Microsoft.Network/virtualNetworks/vnet2"
inboundSubnetId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/hub-rg/providers/Microsoft.Network/virtualNetworks/vnet2/subnets/dnsInboundSubnet",
outboundSubnetId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/hub-rg/providers/Microsoft.Network/virtualNetworks/vnet2/subnets/dnsOutboundSubnet"
},
}
dnszones = [
"privatelink.azure-automation.net",
"privatelink.database.windows.net",
"privatelink.sql.azuresynapse.net",
"privatelink.dev.azuresynapse.net"
]
# Creating DNS zones from file
resource "azurerm_private_dns_zone" "DNS_private_dns_zone" {
for_each = toset(var.dnszones)
name = each.key
resource_group_name = azurerm_resource_group.dnszones_rg.name
}
# Creating virtual network link to DNS zones
resource "azurerm_private_dns_zone_virtual_network_link" "Vnet-dnszone-link" {
for_each = toset(var.dnszones)
name = var.dns_zone_vnet_link_name
resource_group_name = azurerm_resource_group.dnszones_rg.name
private_dns_zone_name = each.value
virtual_network_id = var.resolver_config.value.vnetID[each.key]
}
How can I make so that the Azure Private DNS Zones are deployed once and attached to each vnetID that is specified in the resolver_config variable?