我正在用ARM模板创建一组NSG规则,并尝试更新子网以在嵌套的ARM模板中使用这些NSG规则。模板部署失败,原因是“正在对此资源或从属资源执行另一个操作”。我尝试在嵌套模板中使用“dependsOn”特性,但这并没有起作用。我试过给出NSG的名字和resourceId()
"[resourceId('Microsoft.Network/networkSecurityGroups', variables('NSGName'))]",
不走运的依赖。在尝试更新子网之前,是否有更好的方法等待NSG规则准备就绪?
模板:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"virtualNetName": {
"type": "string",
},
"subnetName": {
"type": "string",
}
},
"variables": {
"NSGName": parameters('subnetName')
"ResourceGroupName": "[resourceGroup().name]"
},
"resources": [
{
"apiVersion": "2017-11-01",
"type": "Microsoft.Network/networkSecurityGroups",
"name": "[variables('NSGName')]",
"location": "[resourceGroup().location]",
"properties": {
"securityRules": [
{
"name": "Allow-Inbound-RDP",
"properties": {
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "3389",
"sourceAddressPrefix": "192.168.0.1/24",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 4050,
"direction": "Inbound"
}
}
]
}
},
{
"apiVersion": "2017-08-01",
"name": "apply-nsg-to-subnet",
"type": "Microsoft.Resources/deployments",
"dependsOn": [
"[resourceId('Microsoft.Network/networkSecurityGroups', variables('NSGName'))]"
],
"properties": {
"mode" : "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"apiVersion" : "2018-03-01",
"type": "Microsoft.Network/virtualNetworks/subnets",
"name": "[concat(parameters('virtualNetName'), '/', parameters('subnetName'))]",
"properties": {
"addressPrefix": "[reference(resourceId(variables('ResourceGroupName'), 'Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetName'), parameters('subnetName')), '2018-03-01').addressPrefix]",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('NSGName'))]"
}
}
}
]
}
}
}
]
}
我相信一个NSG和一个子网更新可以顺利通过,但当我用八个子网更新时就不行了。