I have to update some existing ARM templates to deploy a pair of resources (NSG, VNet) to multiple resource groups, where the resource groups are passed to the template as an array.
Q: How do I make the VNet depend on the NSG that’s in the same resource group?
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"listOfRGs": {
"type": "array",
"defaultValue": ["rg1", "rg2",..."rgN"],
}
},
"resources": [
"copy": [
{
"name": "rgNsgCopyIdx",
"count": "[length(parameters('listOfRGs'))]",
"input": {
"type": "Microsoft.Network/networkSecurityGroups",
"name": "myNSG",
"resourceGroup": "[parameters('listOfRGs')[copyIndex('rgNsgCopyIdx')]]",
.... and some other properties
}
},
{
"name": "rgVNetCopyIdx",
"count": "[length(parameters('listOfRGs'))]",
"input": {
"type": "Microsoft.Network/virtualNetworks",
"name": "myVNET",
"resourceGroup": "[parameters('listOfRGs')[copyIndex('rgVNetCopyIdx')]]",
"dependsOn": [
"<WHAT GOES HERE TO DEPEND ON THE NSG IN THE SAME RESOURCE GROUP>"
]
}
},
]
]
}