Using environment variables in ARM templates

When planning your infrastructure-as-code (IaC) process, we have a variety of ways to deploy several environments from a single source code. Some people will use different “parameters.json files,” others will use pipeline variables, and there are plenty of ways to get the work done. In this article, I will show the combination of parameters and variables in the ARM template. The interesting portion of this method is that I’m going to receive a single parameter called environment, and based on the parameter, I will use a specific variable. Look at the code below, where I introduced the environment and the v_DEV_sample.

environment variabl

When referencing the variable we can use [variables(concat(‘v_’,parameters(‘environment’),’_Sample’))] and that allows us to construct the variable using a parameter file. Let’s imagine that I had a variable for UAT called v_UAT_sample. As long as I pass the right environment, I will get a different value.

environment variabl

In that case, I was deploying a web app, and just for fun, I created a new application setting and used that variable that we defined during execution time — and the result is the proper value for the DEV environment.

ARM templates

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top