How do I modify specific member of array in nested deployment in ARM?

Viewed 239

I have nested deployment which updates IPConfiguration to static. Parent deployment is below showing that several IPconfigurations are created for single NIC. Later in the same parent template a nested deployment is created to set those IPs from dynamic to static. This does not work since every execution of that nested deployment is completely overwrites ipconfigurations which was set in parent scope. I'm confused how to I modify either individual entries for ipconfigs array or modify all of them at the same in a loop.

Parent Deployment

{
        "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)]"
                        }
                    }
                }
            ]
        }
    },

Nested Deployment

            "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]"
                }
            }
        }

Template for nested deployment is below

"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')]"
                        }
                    }
                }
            ]
        }
    }
],
1 Answers

Had to pass to nested deployments all Ips via

   "ips": {
    value": "[reference(concat('Microsoft.Network/networkInterfaces/',variables('nicName')))]"                       
    }

And then inside nested deployment to have a loop over those

            "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)]"
                        }
                    }
                }
            ]
        }
Related