Using conditions in ARM templates when deploying infrastructure-as-code

One of my customers asked for a switch to deploy certain Azure resources based on the environment, and the procedure that we are going over on this blog post will explain in detail how to perform this task. It is a useful trick to keep up your sleeve when deploying your infrastructure-as-code (IaC) with ARM templates. First, in the parameters.json (parameters file), we are going to create a parameter called DeployLogAnalytics, and we can set the value to true or false.

ARM template when deploying infrastructure-as-code

In the Azure template file, we are going to define the parameter to create the link with the parameters file. Although I said true or false are possible values, I defined it as a string type, meaning that any value is possible.

ARM template when deploying infrastructure-as-code

The trick is when deploying the desired resource. I like to use the first line to create the condition. We are defining that this resource between {} will be deployed only if the value of DeployLogAnalytics is true. If it is anything else, the resource will not be deployed.

By adding a single line and using a couple of functions, we were able to create some dynamic in the infrastructure-as-code deployment using 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