2015-12-30 174 views
0

有没有办法在循环中添加依赖项? 我想通过循环添加几个允许所有规则NSG,它失败。 我使用这样的模板:Azure资源管理器:循环依赖

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

    } 

其中allowedCIDRs和allowedCIDRsNames各自9个元件的阵列。

它失败,以下错误:

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: ' 

每次在不同的规则

回答

-1

我假设你想Concat的参数“allowedCIDRs”的价值和复制索引值。在这种情况下,你应该使用下面的语法:

“sourceAddressPrefix”: “[CONCAT(参数( 'allowedCIDRs'),copyIndex())]”

对ARM functionsloops

+0

更多信息不,我想在allowedCIDR中插入值。这部分工作正常。但问题是并非所有的规则都是由这个循环添加的。一些正在停滞,并出现错误:New-AzureResourceGroupDeployment:13:55:12 PM - 资源Microsoft.Network/networkSecurityGroups/securityRules'NSGName/RuleName'失败,并显示'此消息或依赖资源上的另一项操作正在进行中。 Toretrieve状态的操作使用uri:' 也许有一种方法可以在每个循环中添加等待? –

+0

默认情况下,循环尝试并行执行操作。您可能需要将其更改为串行。欲了解更多信息:https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-multiple#serial-copy – BrentDaCodeMonkey