# ARM Templates Demystified

# Intro

Iā€™ve been hearing that a lot of people are having trouble with ARM templates. Either they donā€™t understand them and donā€™t know how to use them, or they do use them but the templates are too hard to use. This feedback really surprised me and calls out for a quick demystification. In this post, Iā€™m going to explain what ARM templates are and why you should care.

# ARM Templates Demystified

First off, it occurred to me that the name might be confusing. ARM here doesnā€™t have anything to do with CPU architecture such as what is used in phones and tablets, which would be an honest misunderstanding. ARM stands for Azure Resource Manager (opens new window), which is how you organize all your stuff on Azureā€”virtual machines, databases, storage accounts, containers, web apps, bots, and more. In Azure, we call your stuff resources.

You will tend to create many related items together in Azure, like a web app and a database will be contained in a single resource group. But what if you had to do this frequently for many different clients? Wouldnā€™t it be nice to have an easy way to keep track of all the repeatable groups of resources you are creating for people? Good news, this is exactly what ARM Templates do!

# What are some real-world scenarios for using ARM Templates?

When you need an easy way to repeat infrastructure deployments on Azure, ARM templates are going to save you a lot of time. If you ever need to share your infrastructure with other peopleā€”like for open source projects or for blogs, tutorials, and documentationā€”ARM templates will be a lifesaver and will let your readers and users replicate what you did. Finally, if you just need a way to keep track of what you deployed on Azure, ARM templates are a great way to help you remember.

# An ARM Template is just a JSON file

This is where ARM templates come in. ARM templates are JSON files that act like blueprints for the related resources you want to deploy together. Youā€™ll also hear this called ā€œinfrastructure as code,ā€ which is geek speak for being able to upload your infrastructure notes to GitHub if you want to. Itā€™s a structured format for keeping track of your Azure infrastructure with some superpowers. The biggest ARM template superpower is that you can use templates to automate your infrastructure deployments because Azure knows how to read them.

In the example below, we are creating an ARM template that creates a Notification Hub. You'll see that it contains things that the deployment needs such as Name, Location, etc.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "namespaceName": {
            "type": "string",
            "metadata": {
                "description": "The name of the Notification Hubs namespace."
            }
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "The location in which the Notification Hubs resources should be deployed."
            }
        }
    },
    "variables": {
        "hubName": "MyHub"
    },
    "resources": [
        {
            "apiVersion": "2014-09-01",
            "name": "[parameters('namespaceName')]",
            "type": "Microsoft.NotificationHubs/namespaces",
            "location": "[parameters('location')]",
            "kind": "NotificationHub",
            "resources": [
                {
                    "name": "[concat(parameters('namespaceName'), '/', variables('hubName'))]",
                    "apiVersion": "2014-09-01",
                    "type": "Microsoft.NotificationHubs/namespaces/notificationHubs",
                    "location": "[parameters('location')]",
                    "dependsOn": [
                        "[parameters('namespaceName')]"
                    ]
                }
            ]
        }
    ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

But more on that later!

# Getting Started

You can make an ARM template in Visual Studio, in Visual Studio Code, or in the Azure portal. The last way is probably the easiest since it walks you through the process. Start creating a resource through the portal the way you normally would, by clicking on the Create Resource on your Azure Portal Dashboard. Now select what you'd like to create. I'm going to create a Web App. Look at the bottom of this page and you'll see Automation options.

But what does that unassuming link labeled Automation options next to it do? Youā€™ve probably never noticed it before or been afraid to mess with it, but if you click on that link, you will be on the road to creating an ARM template for your resource. But you'll have to come back tomorrow for Part 2!