Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Nomenator/2a269044175385f0bb383e5cc66f6a57 to your computer and use it in GitHub Desktop.
Save Nomenator/2a269044175385f0bb383e5cc66f6a57 to your computer and use it in GitHub Desktop.
Deploy multiple resource grops in Azure
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"rgNames": {
"type": "array"
},
"rgLocation": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2018-05-01",
"location": "[parameters('rgLocation')]",
"name": "[parameters('rgNames')[copyIndex()]]",
"copy": {
"name": "rgCopy",
"count": "[length(parameters('rgNames'))]"
}
}
]
}
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"rgNames": {
"value": [
"group1",
"group2",
"group3",
"group4"
]
},
"rgLocation": {
"value": "eastus"
}
}
}
@MaximRouiller
Copy link

@Nomenator

If anyone sees this in the future, when dealing with local files, you have to use the TemplateFile and TemplateParameterFile parameter. Not the Uri kind.

I'll see if we can bring this feedback to the product group managing that cmdlet.

@Nomenator
Copy link
Author

As noted above, the problem is solved by providing the proper command syntax. The correct command invocation to deploy resources at subscription level is as follows: new-AzSubscriptionDeployment -Name <name-of-your-choice> -Location <locationCode> -TemplateFile <path-to-file> -TemplateParameterFile <path-to-another-file>

@Nomenator
Copy link
Author

On a side note, it's curious that the template file is still being read with the -TemplateUri command, as shown by the proper expectation of rgNames parameter value, but the parameter file is not being read with the -TemplateParameterUri, parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment