1

Is there a way to add a dependendency in a loop? I am trying to add several allow all rules to NSG via loop and it fails. I am using such a template:

    {
            "copy": { 
                    "name": "allowCopy", 
                    "count": "[length(parameters('allowedCIDRs'))]" 
                    },  
            "apiVersion": "[variables('apiVersionString')]",
            "type": "Microsoft.Network/networkSecurityGroups/securityRules",
            "name": "[concat(parameters('networkSecurityGroupName'), '/', parameters('allowedCIDRsNames')[copyIndex()])]",
            "location": "[resourceGroup().location]",
              "dependsOn": [
                "[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]"
              ],
                "properties": {                     
                    "description": "[concat('Allow everything from ', parameters('allowedCIDRsNames')[copyIndex()])]",
                    "protocol": "*",
                    "sourcePortRange": "*",
                    "destinationPortRange": "*",
                    "sourceAddressPrefix": "[parameters('allowedCIDRs')[copyIndex()]]",
                    "destinationAddressPrefix": "*",
                    "access": "Allow",
                    "priority": "[copyIndex(100)]",
                    "direction": "Inbound"
                }

    }

where allowedCIDRs and allowedCIDRsNames are arrays of 9 elements each.

And it fails with following error:

New-AzureResourceGroupDeployment : 13:55:12 PM - Resource Microsoft.Network/networkSecurityGroups/securityRules 'NSGName/RuleName' failed with message 'Another operation on this or dependent resource is in progress. Toretrieve status of the operation use uri: '

Each time on different rules

Anton Kuryan
  • 607
  • 6
  • 20

1 Answers1

-1

I assume that you want to concat the value of parameter 'allowedCIDRs' and the copy index value. In that case you should use the following syntax:

"sourceAddressPrefix": "[concat(parameters('allowedCIDRs'),copyIndex())]"

for more information on ARM functions and loops

  • No, I want to insert value in allowedCIDRs. This part works correctly. But the problem is that not all rules are added by this loop. Some are stalling with error: New-AzureResourceGroupDeployment : 13:55:12 PM - Resource Microsoft.Network/networkSecurityGroups/securityRules 'NSGName/RuleName' failed with message 'Another operation on this or dependent resource is in progress. Toretrieve status of the operation use uri: ' Maybe there is a way to add a wait in each loop pass? – Anton Kuryan Dec 31 '15 at 16:52
  • 2
    A loop tries to do things in parallel by default. You may need to change this to serial. For more info: https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-multiple#serial-copy – BrentDaCodeMonkey Jun 27 '17 at 20:20