我有一个ARM模板和参数文件,该文件已在Azure中成功部署了加入域的VM。
[它需要更新以部署500个VM,它们的名称后缀为-01,-02,-03等。我试图在模板的资源部分中使用复制对象,但是遇到了问题,所以我想回顾一下我接近这个。
https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/create-multiple-instances
原始ARM模板中的代码段
"resources": [
{
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"apiVersion": "[variables('apiVersion')]",
"tags": "[parameters('tag')]",
"location": "[parameters('location')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[parameters('subnetID')]"
}
}
}
]
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmSettings').vmNamePrefix]",
"apiVersion": "2017-03-30",
"tags": "[parameters('tag')]",
"location": "[parameters('location')]",
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[variables('vmSettings').vmNamePrefix]",
"adminUsername": "[variables('vmSettings').adminUserName]",
"adminPassword": "[variables('vmSettings').adminPassword]"
},
"storageProfile": {
"imageReference": "[variables('imageReference')]",
"osDisk": {
"name": "[concat(parameters('dnsLabelPrefix'), '-os')]",
"caching": "ReadWrite",
"createOption": "FromImage"
},
"dataDisks": [ ]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
]
},
"name": "[concat(variables('vmSettings').vmNamePrefix), copyIndex()]"
A1。您需要同时在VM和NIC(而不是OS Disk)中添加副本。
A2。我建议您仅将VM名称后缀与复制索引一起使用,而不要像01、02等那样使用。您可以看到函数copyIndex()。然后,您可以像这样更改提供的Nic和VM的模板:
"resources": [
{
"type": "Microsoft.Network/networkInterfaces",
"name": "[concat(variables('nicName'), '-', copyIndex())]",
"apiVersion": "[variables('apiVersion')]",
"tags": "[parameters('tag')]",
"location": "[parameters('location')]",
"copy": {
"name": "nicLoop",
"count": "[parameters('numberOfInstances')]"
},
"properties": {
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[parameters('subnetID')]"
}
}
}
]
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"name": "[concat(variables('vmSettings').vmNamePrefix, '-', copyIndex()]",
"apiVersion": "2017-03-30",
"tags": "[parameters('tag')]",
"location": "[parameters('location')]",
"copy": {
"name": "vmLoop",
"count": "[parameters('numberOfInstances')]"
},
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[variables('vmSettings').vmNamePrefix]",
"adminUsername": "[variables('vmSettings').adminUserName]",
"adminPassword": "[variables('vmSettings').adminPassword]"
},
"storageProfile": {
"imageReference": "[variables('imageReference')]",
"osDisk": {
"name": "[concat(parameters('dnsLabelPrefix'), '-os')]",
"caching": "ReadWrite",
"createOption": "FromImage"
},
"dataDisks": [ ]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', concat(variables('nicName'), '-', copyIndex())]"
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'), '-', copyIndex())]"
]
},