从ARM模板设置的虚拟机规模中获取虚拟机的内网IP,可以通过以下步骤实现:
"variables": {
"vmCount": 3
},
"resources": [
{
"name": "[concat('vm', copyIndex())]",
"type": "Microsoft.Compute/virtualMachines",
"copy": {
"name": "vmLoop",
"count": "[variables('vmCount')]"
},
"properties": {
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"osProfile": {
"computerName": "[concat('vm', copyIndex())]",
"adminUsername": "adminUser",
"adminPassword": "adminPassword"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2016-Datacenter",
"version": "latest"
},
"osDisk": {
"name": "osdisk",
"createOption": "FromImage",
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', concat('nic', copyIndex()))]"
}
]
}
}
}
],
"outputs": {
"vmIPs": {
"type": "array",
"value": "[reference(concat('vm', copyIndex())).networkProfile.networkInterfaces[0].ipConfigurations[0].privateIPAddress]"
}
}
在上述示例中,通过使用"copyIndex()"函数和"concat()"函数,可以为每个虚拟机生成唯一的名称。然后,在"outputs"字段中,使用"reference()"函数获取每个虚拟机的内网IP。
az vm show -g <resource-group-name> -n <vm-name> --query "privateIps" -o tsv
其中,"<resource-group-name>"是资源组的名称,"<vm-name>"是虚拟机的名称。
总结起来,通过在ARM模板中定义虚拟机规模,并使用相应的函数和表达式来获取每个虚拟机的内网IP,可以实现从ARM模板设置的虚拟机规模中获取虚拟机的内网IP。
领取专属 10元无门槛券
手把手带您无忧上云