我目前对具有一个虚拟网络资源的多个环境使用一个模板,通过循环不同的配置来创建多个 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。