Kamsiinov
Kamsiinov

Reputation: 1486

Azure ARM template depend on resources in copy loop

I am creating ARM template which takes in hash table of subnets and creates those. However, it looks that I need to wait for the first subnet to be ready before creating the second etc. But I do not know how I could depend on the previous subnet in copy loop. My template resource looks like this currently:

      {
    "apiVersion": "2018-06-01",
    "type": "Microsoft.Network/virtualNetworks/subnets",
    "name": "[concat(parameters('vnetName') , '/' , parameters('subnets').settings[copyIndex()].name)]",
    "location": "[variables('location')]",
    "copy": {
      "name": "subnetLoop",
      "count": "[variables('subnetcount')]"
    },
    "dependsOn": ["[parameters('vnetName')]",
    "[resourceId(variables('rgname'), 'Microsoft.Network/virtualNetworks/subnets', parameters('vNetName'), parameters('subnets').settings[copyIndex()].name)]"
  ],
    "properties": {
      "addressPrefix": "[parameters('subnets').settings[copyIndex()].addressPrefix]",
       }

Which does not work because the first subnet cannot reference itself.

Upvotes: 5

Views: 1811

Answers (1)

4c74356b41
4c74356b41

Reputation: 72211

you can use "mode": "serial" to workaround that.

"copy": {
  "name": "subnetLoop",
  "count": "[variables('subnetcount')]",
  "mode": "serial"
},

https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-multiple#resource-iteration

but you really need to look at properties loop, check this link:

https://learn.microsoft.com/en-us/azure/architecture/building-blocks/extending-templates/objects-as-parameters#using-a-property-object-in-a-copy-loop

Upvotes: 5

Related Questions