When developing your ARM templates in infrastructure-as-code (IaC), I like to narrow down the options for the cloud administrators or teams that will consume my ARM templates. The location of your resources is a good candidate for this kind of optimization. When managing the location in the parameters section of our ARM templates, the first thing is to have a default value, which would be your default region (in my case Canada Central is home), and make sure that we allow the second geopolitical region (in my case the French region Canada East).
If someone tries to input anything different than Canada regions, the deployment will fail and inform the possible values, which is a good thing.
Note: In my scenario, I use the code because that helps me with the naming convention as well. That is the reason that I don’t ask to provide the full name “CanadaCentral” or “CanadaEast.”
The second thing is to create a variable with an if condition that will store the complete name of the region based on the region code provided in the parameters.
The third and final touch is to use that variable when defining the location in the resources being provisioned, as depicted in the image below.
By playing with location parameters and a variable, we can guarantee that our ARM template will always get valid regions, and we will force a default region if none is provided. All resources being provisioned will take advantage of the location.
More Quick Tips articles
- Reading text files with PowerShell and Linux bash shell
- Integrating Microsoft Defender with Cloud App Security
- New from Microsoft: Azure Security Center onboarding guide
- Fixing Azure Key Vault when moving to a different tenant
- Restore Azure Key Vault using just two PowerShell cmdlets