如何创建多个私有DNS区域,然后在每个区域上创建多个私有DNS虚拟链接,用于Terraform Azure中的每个循环

vi4fp9gy  于 2023-04-12  发布在  其他
关注(0)|答案(1)|浏览(126)

创建多个专用DNS区域,然后在每个区域上创建多个专用DNS虚拟链接,用于Terraform azure中的每个循环。并且我无法在每个区域上创建多个虚拟网络链接。

variable "privateDnsZones" {
  type = map(object({
    virtualNetworksID = list(string)
  }))
  default = {
    "privatelink.monitor.azure.com" = {
      virtualNetworksID = [
        "",
        ""
      ]
    },
    "privatelink.oms.opinsights.azure.com" = {
      virtualNetworksID = [
        "",
        ""
      ]
    }
  }
}

resource "azurerm_private_dns_zone" "privateDnsZone" {
  for_each            = var.privateDnsZones
  name                = each.key
  resource_group_name = data.azurerm_resource_group.existing_RG.name
  tags                = var.resource_tags
  
}

resource "azurerm_private_dns_zone_virtual_network_link" "privateDnsZone_link" {
    for_each =
  name                  = 
  resource_group_name   = 
  private_dns_zone_name = 
  virtual_network_id    = 
}
irlmq6kh

irlmq6kh1#

如果没有测试,它应该大致如下:

locals {
  # flatten ensures that this local value is a flat list of objects, rather
  # than a list of lists of objects.
  zones_vnets = flatten([
    for zone_key, zone in var.privateDnsZones: [
      for vnetId in zone.virtualNetworksID : {
        zoneId = azurerm_private_dns_zone.privateDnsZone[zone_key].id
        vnetId = vnetId
      }
    ]
  ])
}

resource "azurerm_private_dns_zone_virtual_network_link" "privateDnsZone_link" {
  for_each = {
    for zone in local.zones_vnets: "${zone.zoneId}.${zone.vnetId}" => zoneLink
  }
  name                  = each.key
  resource_group_name   = "foobar-rg"
  private_dns_zone_name = each.value.zoneId
  virtual_network_id    = each.value.vnetId
}

相关问题