我有嵌套部署,它将IPConfiguration更新为static.下面的父部署显示为单个NIC创建了多个IP配置.稍后在同一父模板中,将创建嵌套部署以将这些IP从动态设置为静态.这不起作用,因为每次执行该嵌套部署都会完全覆盖在父作用域中设置的ipconfiguration.我很困惑如何修改ipconfigs数组的单个条目或在循环中修改所有条目.
家长部署
{
"name": "[variables('NICName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2018-04-01",
"location": "[variables('VMResourceGroupLocation')]",
"properties": {
"copy": [
{
"name": "ipconfigurations",
"count": "[parameters('niccount')]",
"input": {
"name": "[concat('ipconfig',copyIndex('ipconfigurations'))]",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic",
"primary": "[equals(copyIndex('ipconfigurations'),0)]"
}
}
}
]
}
},
嵌套部署
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-08-01",
"copy": {
"name": "deploymentLoop",
"count": "[parameters('niccount')]"
},
"name": "[concat('ipconfig', copyIndex('deploymentloop'))]",
"dependsOn": [
"[variables('NICName')]"
],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "https://raw.githubusercontent.com/artisticcheese/artisticcheesecontainer/master/updateip.json",
"contentVersion": "1.0.0.0"
},
"parameters": {
"nicName": {
"value": "[variables('nicName')]"
},
"ipConfigName": {
"value": "[concat('ipconfig', copyIndex('deploymentloop'))]"
},
"SubnetRef": {
"value": "[variables('SubnetRef')]"
},
"privateIp": {
"value": "[reference(concat('Microsoft.Network/networkInterfaces/', variables('nicName'))).ipConfigurations[copyIndex('deploymentloop')].properties.privateIPAddress]"
}
}
}
嵌套部署的模板如下所示
"resources": [
{
"type": "Microsoft.Network/networkInterfaces",
"name": "[parameters('nicName')]",
"apiVersion": "2018-03-01",
"location": "[parameters('location')]",
"properties": {
"ipConfigurations": [
{
"name": "[parameters('ipconfigName')]",
"properties": {
"privateIPAllocationMethod": "Static",
"privateIPAddress": "[parameters('privateIp')]",
"subnet": {
"id": "[parameters('subnetRef')]"
}
}
}
]
}
}
],
最佳答案 不得不通过所有Ips传递到嵌套部署
"ips": {
value": "[reference(concat('Microsoft.Network/networkInterfaces/',variables('nicName')))]"
}
然后在嵌套部署中进行循环
"properties": {
"copy": [
{
"name": "ipconfigurations",
"count": "[parameters('niccount')]",
"input": {
"name": "[concat('ipconfig',copyIndex('ipconfigurations'))]",
"properties": {
"privateIPAllocationMethod": "Static",
"privateIPAddress": "[parameters('ips').ipConfigurations[copyIndex('ipconfigurations')].properties.privateIPAddress]",
"subnet": {
"id": "[parameters('subnetRef')]"
},
"primary": "[equals(copyIndex('ipconfigurations'),0)]"
}
}
}
]
}