如何在 ARM 的嵌套部署中修改数组的特定成员?
How do I modify specific member of array in nested deployment in ARM?
我有嵌套部署,可将 IPConfiguration
更新为静态。下面的父部署显示为单个 NIC 创建了多个 IPconfigurations
。稍后在同一父模板中创建嵌套部署以将这些 IP 从 dynamic
设置为 static
。这不起作用,因为该嵌套部署的每次执行都会完全覆盖在父范围中设置的 ipconfigurations
。我很困惑如何修改 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)]"
}
}
}
]
}
我有嵌套部署,可将 IPConfiguration
更新为静态。下面的父部署显示为单个 NIC 创建了多个 IPconfigurations
。稍后在同一父模板中创建嵌套部署以将这些 IP 从 dynamic
设置为 static
。这不起作用,因为该嵌套部署的每次执行都会完全覆盖在父范围中设置的 ipconfigurations
。我很困惑如何修改 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)]"
}
}
}
]
}