0

我正在创建一个 ARM 模板,将可变数量的备份域控制器部署到现有的虚拟网络。我需要更改现有虚拟网络的 DNS 服务器。问题是我的虚拟网络彼此具有完全不同的子网,当我部署以下资源时,现有子网消失了。如何只更改虚拟网络的 DNS 服务器属性,而不影响其他属性?

  "resources": [
    {
      "name": "[parameters('existingVnetname')]",
      "type": "Microsoft.Network/virtualNetworks",
      "location": "[parameters('location')]",
      "apiVersion": "2016-10-01",
      "tags": {
        "displayName": "UpdateVNetDNS2"
      },
      "dependsOn": [
        "ConfiguringBDCloop"
      ],
      "condition": "[parameters('deployBackupDCs')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[parameters('existingVnetAddressRange')]"
          ]
        },
        "dhcpOptions": {
          "dnsServers": "[take(variables('privateIParray'),variables('DNSref'))]"
        },
        "subnets": [
          {
            "name": "[parameters('existingSubnetName')]",
            "properties": {
              "addressPrefix": "[parameters('existingSubnetAddressRange')]"
            }
          }
        ]
      }
    }
]

我知道我可以指定现有子网,但是我有很多子网名称和地址范围完全不同的虚拟网络,通过参数指定它们将是一场噩梦。

4

1 回答 1

0

我目前对具有一个虚拟网络资源的多个环境使用一个模板,通过循环不同的配置来创建多个 vNet。

参数包含这些 vNet 的 vNet 前缀和子网前缀。例如:

"virtualNetworkPrefixHub": {
    "type": "string",
    "metadata": {
        "description": "Specify the Virtual Network Prefix for the Hub vNet to create or to be used"
    },
    "allowedValues": [
        "192.168.0.0/25",
        "192.168.32.0/25",
        "192.168.56.0/25",
        "192.168.64.0/25",
        "192.168.96.0/25",
        "192.168.120.0/25"
    ]
},
"virtualNetworkPrefixMgmt": {
    "type": "string",
    "metadata": {
        "description": "Specify the Virtual Network Prefix for the Mgmt vNet to create or to be used"
    },
    "allowedValues": [
        "192.168.0.128/25",
        "192.168.32.128/25",
        "192.168.56.128/25",
        "192.168.64.128/25",
        "192.168.96.128/25",
        "192.168.120.128/25"
    ]
},
"subnet0PrefixHub": {
    "type": "string",
    "metadata": {
        "description": "Specify the the Subnet Prefix for the wan Subnet in the Hub vNet"
    },
    "allowedValues": [
        "192.168.0.0/27",
        "192.168.32.0/27",
        "192.168.56.0/27",
        "192.168.64.0/27",
        "192.168.96.0/27",
        "192.168.120.0/27"
    ]
},
"subnet1PrefixHub": {
    "type": "string",
    "metadata": {
        "description": "Specify the the Subnet Prefix for the lan Subnet in the Hub vNet"
    },
    "allowedValues": [
        "192.168.0.32/27",
        "192.168.32.32/27",
        "192.168.56.32/27",
        "192.168.64.32/27",
        "192.168.96.32/27",
        "192.168.120.32/27"
    ]
},
"subnet0PrefixMgmt": {
    "type": "string",
    "metadata": {
        "description": "Specify the the Subnet Prefix for the adds Subnet in the Mgmt vNet"
    },
    "allowedValues": [
        "192.168.0.128/28",
        "192.168.32.128/28",
        "192.168.56.128/28",
        "192.168.64.128/28",
        "192.168.96.128/28",
        "192.168.120.128/28"
    ]
},
"subnet1PrefixMgmt": {
    "type": "string",
    "metadata": {
        "description": "Specify the the Subnet Prefix for the Build Subnet in the Mgmt vNet"
    },
    "allowedValues": [
        "192.168.0.144/28",
        "192.168.32.144/28",
        "192.168.56.144/28",
        "192.168.64.144/28",
        "192.168.96.144/28",
        "192.168.120.144/28"
    ],
    "defaultValue": ""
}

我将每个 vNet 的配置数组定义为一个复杂变量。您可以在此处为适当的 vNet 定义 DNS 服务器,例如

"vnet-settings": [
    {
        "name": "[concat('vn-hub')]",
        "dnsServers": "[variables('dnsServers')]",
        "location": "[parameters('location')]",
        "prefix": "[parameters('virtualNetworkPrefixHub')]",
        "subnets": [
            {
                "name": "oob",
                "properties": {
                    "addressPrefix": "[parameters('subnet0PrefixHub')]"
                }
            },
            {
                "name": "GatewaySubnet",
                "properties": {
                    "addressPrefix": "[parameters('subnet1PrefixHub')]"
                }
            }
        ]
    },
    {
        "name": "[concat('vn-mgmt')]",
        "dnsServers": "[variables('dnsServers')]",
        "location": "[parameters('location')]",
        "prefix": "[parameters('virtualNetworkPrefixMgmt')]",
        "subnets": [
            {
                "name": "adds",
                "properties": {
                    "addressPrefix": "[parameters('subnet0PrefixMgmt')]"
                }
            },
            {
                "name": "build",
                "properties": {
                    "addressPrefix": "[parameters('subnet1PrefixMgmt')]"
                }
            }
        ]
    }
]

虚拟网络资源如下所示:

"resources": [
    {
        "name": "[variables('vnet-settings')[copyIndex()].name]",
        "copy": {
            "name": "vnetLoop",
            "count": "[length(variables('vnet-settings'))]"
        },
        "type": "Microsoft.Network/virtualNetworks",
        "location": "[variables('vnet-settings')[copyIndex()].location]",
        "apiVersion": "2017-06-01",
        "dependsOn": [],
        "tags": {
            "displayName": "virtualNetworks"
        },
        "properties": {
            "addressSpace": {
                "addressPrefixes": [
                    "[variables('vnet-settings')[copyIndex()].prefix]"
                ]
            },
            "dhcpOptions": {
                "dnsServers": "[variables('vnet-settings')[copyIndex()].dnsServers]"
            },
            "subnets": "[variables('vnet-settings')[copyIndex()].subnets]"
        }
    }
]

希望这可以帮助。

PT。

于 2018-06-20T09:40:12.587 回答