我正在创建一个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')]"
}
}
]
}
}
]
我知道我可以指定现有子网,但是我有很多虚拟网络具有完全不同的子网名称和地址范围,通过参数指定它们将是一场噩梦。
答案 0 :(得分: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。