ARM Templates

Learn about the implementation of IaC with ARM templates.

As you know, IaC is an infrastructure-agnostic term. Each cloud, including Microsoft, has its own way of implementing IaC; Azure Resource Manager (ARM) templates is the Azure way.

Although you can use various other tools like Terraform to provision and manage Azure resources using an IaC approach, ARM templates is the system built by Microsoft specifically for Azure.

Now, you’re going to learn Infrastructure as Code (IaC) the Microsoft way with ARM templates.

ARM templates: Infrastructure as Code

What is an ARM template? Think of an ARM template as a description of how your Azure resources should look. Templates are JSON files built with a specific schema that dictates how to describe each Azure resource you’d like to build. Unlike building Azure resources with a script, for example, you don’t tell Azure how to build the resources. You simply tell it what to build by building a template; ARM then takes care of the rest.

When the templates are built, you will then deploy that template to a resource group known as an ARM deployment. The deployment then reads the template and gets busy building all of the resources you’ve defined.

Most ARM templates will deploy to resource groups. Templates also support deployment to subscriptions too.

Like all other Infrastructure as Code methodologies, ARM templates are idempotent. When the resources you’d like to build do not exist and you deploy an ARM template, the deployment creates all of the resources from scratch. Once the resources are built, you can then run the deployment over and over again without modifying it. ARM is smart enough not to attempt to recreate the same resources or throw an error when the resource already exists. ARM supports a concept called immutable_infrastructureImmutable_infrastructure .

The schema

An ARM template can’t be any ol’ JSON file. It must adhere to a strict schema so that the deployment understands what and how to build the resources.

Below, you’ll see the main nodes of a template and an explanation of each.

    "$schema": "",
    "contentVersion": "",
    "parameters": {  },
    "variables": {  },
    "functions": [  ],
    "resources": [  ],
    "outputs": {  }
  • $schema: This required attribute represents the JSON file used to validate the schema. For resource group deployments, it will look like

  • contentVersion: This is an optional, user-defined attribute that represents the version of the ARM template itself. This attribute is great for keeping track of changes made to the ARM template.

  • parameters: An ARM template doesn’t have to contain static values. You can pass parameters to the template at run time. This is an optional node that defines parameters to pass to the template at runtime.

  • variables: The template schema allows for variables. This is an optional node that defines any variables to reference throughout the template.

  • functions: A useful feature of ARM templates is the ability to run expressions. In this optional attribute, you can define common expressions and call throughout the template.

  • resources: This is the required section that will be, by far, the largest. This section is where you will define all of the resources to deploy to Azure. Bookmark the Define resources in Azure Resource Manager templates Microsoft docs page for the schema and for each resource.

  • outputs: By default, ARM template deployments don’t return anything. If you need to return anything from the template like a dynamically generated component, this optional node is where you will do that.

Use examples and syntax ‘helpers’

When you create your first ARM template, you will be overwhelmed. You’ll be overwhelmed with the sheer complexity of the JSON. This complexity isn’t unwarranted. There is a lot of configuration that goes into building Azure resources.

The best way to learn to build ARM templates is by example. You can never remember each resource and all of the attributes associated with it. Come up with the resource you’d like to add to an ARM template and look for it in the Azure Quickstart Templates GitHub repo. This GitHub repo provides many different ARM templates under many different scenarios. It’s an excellent source for examples.

Also, use syntax “helpers” wherever you can to guide you as you write. If you’re using Visual Studio Code (VS Code) to create a template, install the Azure Resource Manager (ARM) Tools for Visual Studio Code extension. The VS Code extension gives VS Code the ability to intelligently understand ARM templates like other languages. The extension provides Intellisense, syntax-highlighting, and more, giving you pointers as you write.

You’ll find that writing an ARM template itself isn’t complicated, but it is complex. ARM templates can be huge and contain many different types of resources that have their own schema. Just know, you only have to build the template once unless you need to change how the resources are deployed.

Get hands-on with 1000+ tech skills courses.