Dummies guide to Automating Azure Deployments with ARM Templates

Rajesh Rajamani
CloudForDummies
Published in
6 min readOct 22, 2021

ARM stands for Azure Resource Manager. This article is the first of a series in Azure Deployment Automation.

ARM provides a simple and efficient way to declare Azure resources that you wish to create in your subscription in a json file and deploy them using Azure CLI.

This approach of declaring resources and deploying them programmatically is called as Infrastructure as Code.

On this note, I have written an introduction to Terraform a leading open-source Infrastructure as Code tool which may want to take a look.

Too much to digest ? . Let’s take it step by step.

Before we proceed further , the following are required to complete this tutorial successfully.

  1. Microsoft Azure Subscription . If you are pro or a novice , it’s always good to have your own free subscription of yours to test things out. If you have still not got one, I guess its time to get one.

2. Azure CLI version 2.20.0 or above. Doesn’t matter if your laptop runs windows or linux . Even with windows laptops you can follow the tutorial on WSL ( Windows Subsystem for Linux ) . If you have still dont know what is WSL , good idea to take a look.

3. Docker . This is optional if you are not able to have the latest version or atleast the version (2.20.0) required to run the commands in this tutorial.

I had issues with my linux laptop where my azure cli version was stuck in 2.0.8 and was refusing to upgrade . So I went the docker way . Other than that the steps are going to be the same.

4. VS Code or similar editor. Again totally your choice. I prefer VS Code for the add-ons it provides to aid .

Let’s deploy some infrastructure with code shall we ?

For this tutorial I’m using a docker image of Azure CLI. If you are following this with the docker image of azure CLI , please ensure to run the docker image before firing the commands. If you have successfully installed the latest version of Azure CLI , then you can ignore the docker specific steps.

Docker specific steps:

a. Pull the azure cli image

docker pull mcr.microsoft.com/azure-cli

b. Run the azure cli image

Note : If you are running the azure cli on Docker you’ll need an additional step to allow the docker image to access the deployment files ( from Step 3 below )saved in local folder . The following command enables you to do that.Replace the placeholder highlighted with the correct path

docker run -it -v <your_local_folder_where_the_files_are>:/mnt mcr.microsoft.com/azure-cli

Step 1: Check if you have azure cli installed by running the following command on your command line

az version

Step 2: Login to your azure subscription from your cli with

az login

At this step you should get a confirmation as follows

Step 3: Let’s first create a resource group to group up the resources from command line

az group create --name rg-demo-arm --location eastus

If you have the right permissions to your subscription you should get a success message.

Step 4: Let’s create a deployment configuration file for creating a storage group.

Here I’ll be using VS Code and it’s inbuilt capabilities that aid in creating ARM Templates. If you don’t use VS Code , simply copy paste the pre-built file that I have below and proceed.

Creating the same file in VS Code is pretty intuitive. Create a blank file named azresourcedeploy.json and open it in VS Code.

a. Now start typing ar and you start getting suggestions . This is enabled by VS Code loading ARM Schema definitions in the background.

A blank template looks like this and for simplicity we are only going to use parameters and resources for this tutorial .

b. Creating a parameter that we can use.

c. At this stage , VS Code also allows you to create a separate parameter file where you can group all your parameters . Remember , it is totally optional , however it is a best practice so one should follow it.

You can also create this manually . Simply copy paste the file in your folder.

Please take care to change the values for the paramter.

Step 5: Show Time

Assuming you have both the files are ready , let’s fire the deployment command.

Before we fire the command , for those of you who are running this on docker , just a last check to ensure that the files are indeed available within the docker environment.

Note: This doesn’t mean the files are copied , but we are mounting the path temporarily during the time when the docker image is running.

This is a very powerful technique and you can learn more about mounting volumes here.

Let’s fire the deployment command now . Before that look at the highlighted parameters.

az deployment group create --resource-group rg-demo-arm --template-file azresourcedeploy.json --parameters azresourcedeploy.parameters.json

At this stage , you should get the following prompt which will mean that you are all set and the resources are getting deployed.

Once the deployment is completed you should get a message as follows.

Step 6: Let’s verify the resources on Azure portal.

Resource Group

Storage Account within in the Resource Group

So with that we have successfully deployed a resource to Azure subscription with Azure CLI and ARM templates.

Step 7: Cleanup time.

As this is a tutorial ,with the command below let’s delete the resources we created.

az group delete --name rg-demo-arm

You will be prompted to confirm

Closing thoughts:

  1. Deployment and maintenance of Cloud infrastructure is critical to production efficiency , business continuity , disaster recovery .
  2. ARM Templates and Azure CLI provides a way to enable versioning , standardization to resource deployment activities.

Similar tools for GCP and AWS

--

--