Phani
Phani

Reputation: 71

ARM template: Way to workaround for nested copy in variable section

I am using azure-arm template and below attempt in creating copy iteration failed in variables section. This is giving me error, saying nested is not supported, Am I missing anything, if nested copy is not supported, how to go ahead in creating array of objects containing array.

    "copy": [
      {
        "name": "VmInfo",
        "count": "[parameters('vmCount')]",
        "input": {
          "skuQualVmName": "[concat(parameters('vmName'), '-vm-', copyIndex('VmInfo',1))]",
          "copy": [
            "name": "vmInterfaceNames",
            "count": "[parameters('nicCountPerVm')]",
            "input": "[concat(parameters(vmName), '-vm-', copyIndex('VmInfo',1), '-nic-', copyIndex('vmInterfaceNames',1))]"
        ]
        }
      }
    ],

Also I want to know if mutliple copy statements are supported in variables, like below

....
"copy": [
            {
                "name": "publicIpAdressResourceArray",
                "count": "[parameters('vmCount')]",
                "input": {
                    "id": "[resourceId('Microsoft.Network/publicIPAddresses',concat('primary-ip-', parameters('vmNames')[copyIndex('publicIpAdressResourceArray')]))]"
               }
            }
        ]
    },
   "copy": [
      {
        "name": "networkInterfaceNames",
        "count": "[mul(parameters('vmCount'),parameters('nicCountPerVm'))]",
        "input": "[concat(  parameters('vmNameSubString'), '-vm-', div(copyIndex('networkInterfaceNames'),parameters('nicCountPerVm')), '-nic-', mod(copyIndex('networkInterfaceNames'),parameters('nicCountPerVm')))]"
      }
    ],
....

Upvotes: 1

Views: 877

Answers (1)

4c74356b41
4c74356b41

Reputation: 72211

first copy is correct, for the second question, you can do this:

"copy": [
    {
        "name": "firstvar",
        xxx
    },
    {
        "name": "secondvar",
        yyy
    }
]

so just use a single copy statement for all the var iterations you need. if you are looking for a property of a variable, to be an array that needs to be generated\calculated - you can use nested deployments:

  1. create base variable
  2. pass it into a nested deployment
  3. pass all the relevant data to calculate your second array
  4. create a new variable in the nested deployment with the desired structure
  5. output it and use it

but, probably, your best bet - is calculating this outside of an arm template.

Upvotes: 1

Related Questions