Azure Resource Manager Template defines the resources you need to deploy for your solution. First of all, you must know that an Azure Resource Manager Template is a just a simple JSON file. JSON is an open-standard file format derived from JavaScript. Note that a JSON file is a collection of name/value pairs. Visual Studio is probably one of the best tool to create your own Azure RM Templates, so you can download it from here: https://www.visualstudio.com/downloads/ but you can also use VS Code (free and cross-platform) or use your favorite tool in order to create ARM templates.

Table of Contents

  1. Azure Resource Manager (ARM) Templates
  2. Building or Editing Your Own Template
  3. How to Deploy ARM Templates?
  4. Conclusion

Before going deeper, I advise you to read my article on Vembu about Azure Resource Manager: https://www.bdrsuite.com/blog/introducing-azure-resource-manager/. In the previous article I wrote some few lines about Templates, so in this article I will explain how to use ARM templates.

Azure Resource Manager (ARM) Templates

Protect Your Data with BDRSuite

Cost-Effective Backup Solution for VMs, Servers, Endpoints, Cloud VMs & SaaS applications. Supports On-Premise, Remote, Hybrid and Cloud Backup, including Disaster Recovery, Ransomware Defense & more!

ARM is the toolset Microsoft has added to Azure for provisioning and controlling resources in Azure. ARM templates describe a resource and related dependencies. So let’s start with the anatomy of an ARM template. It will contain five main sections: schema, parameters, variables, resources, and outputs.

Here is the basic structure of an ARM template:

Azure Resource Manager Templates

Download Banner

Schema: This item is mandatory and the value must be the location of JSON schema file. More information here: https://github.com/Azure/azure-resource-manager-schemas/

ContentVersion: It is a mandatory item. It is just a version number used to track the version of your template.

Parameters: Parameters are values entered before the deployment can start. They will customize the deployment. For example, a parameter can the admin password, a VM size, …

Azure Resource Manager Templates

Variables: They will simplify your template and allow you to store values.

Azure Resource Manager Templates

Resources: Resources define a collection of resources that you plan to deploy as a part of the template deployment.

Azure Resource Manager Templates

Outputs: The outputs element is used to return data and objects from a deployment. (not required). These are values that can be passed to another deployment such as an IP Address.

Building or Editing Your Own Template

To perform this task, I will use VS Code. Let’s start by downloading and installing VS Code.
Once the installation is completed, install the Azure RM Tools: https://marketplace.visualstudio.com/items?itemName=msazurermtools.azurerm-vscode-tools

Azure Resource Manager Templates

Click “Install” and this will download and install the language support for ARM JSON templates.

Azure Resource Manager Templates

To finish, copy the contents of the file from GitHub: https://github.com/Azure/azure-xplat-arm-tooling/blob/master/VSCode/armsnippets.json and open VS Code. Navigate to File, Preferences, User Snippets and type “JSON”. Paste the contents of the file, save and close the user snippets file. That’s all!

Now, we will test the VS Code extension. You can download a sample template from https://github.com/Azure/azure-quickstart-templates or use your own template from the Azure Portal.

In order to export your template, go to the Azure Portal, select your Virtual Machine and click “Automation Script”:

Azure Resource Manager Templates

And then click “Download”

Azure Resource Manager Templates

Now, you can open the “template.json” file and insert a new line in order to confirm that VS Code will display a whole list of options. These options are the available ARM Template snippets.

Azure Resource Manager Templates

Ok, now you can use VS Code to write your ARM template or just to edit existing templates to suit your needs.

Visualize your Templates

Let’s take the following example from GitHub. I want to visualize this template in a graphic view. This template will create a new Windows VM and create a new AD domain. So, click “Visualize” and you will be redirected to http://armviz.io

Azure Resource Manager Templates

What is ARMVIZ.io?

It is a visual way of visualizing, editing, and saving Azure Resource Manager Templates. Thanks to ARMVIZ, you can edit your template through a web browser and download it. But one of the cool feature is the designer view. You will be able to display a nice schema of your template, and if you click on a resource, ARMVIZ will display the related JSON code.

Azure Resource Manager Templates


How to Deploy ARM Templates?

Deploying your own templates can be done via Windows PowerShell or through the Azure Portal. In this guide, I will use an existing template which is a basic ARM template that you can download from: https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-simple-windows.

Azure Resource Manager Templates

Click “Create Templates”:

Azure Resource Manager Templates

Enter the name of your template and a description and click “OK”. Paste the contents of your JSON file that you download previously from GitHub and click “Create”.

You can now click “Deploy” in order to deploy a simple Windows VM.

Azure Resource Manager Templates

Finally, Azure will ask you some parameters. So you just have to enter the following required values:

  • Admin Username
  • Admin Password
  • DNS Label Prefix
  • Windows OS Version

or you can also edit the template by clicking “Edit Template”.

Azure Resource Manager Templates

If you prefer to deploy your Template with PowerShell, it is pretty easy. The only prerequisite is to install Azure RM module from the PowerShell Gallery. Run the Install-Module cmdlet:

Azure Resource Manager Templates

Now, you must use the New-AzureRMResourceGroupDeployment cmdlet in order to deploy the template. You must specify a Resource Group and the JSON file. PowerShell will ask you to enter the required parameters:

Azure Resource Manager Templates

Now, let’s check the deployment, open Azure Portal and go to your Resource Group. Below, I can confirm that a new VM has been successfully created:

Azure Resource Manager Templates

Of course you can create from scratch your ARM templates, but Microsoft provides an ARM Template Gallery which contains 626 Templates created by the community and partners: https://azure.microsoft.com/en-us/resources/templates/

Useful links

Below are some useful links that can help you to start with Azure Resource Manager Templates:

From GitHub: Azure Quickstart Templates https://github.com/Azure/azure-quickstart-templates
From Microsoft: Best practices for creating Azure Resource Manager templates https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-template-best-practices
From Microsoft: Understand the structure and syntax of Azure Resource Manager templates: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates

Conclusion

Azure Resource Manager Templates are really helpful in order to automate your VMs deployments. Thanks to ARM Templates, you can easily automate your daily tasks and optimize the use of your time.

Interested in trying BDRSuite? Try Now on a 30-days free trial: https://www.bdrsuite.com/vembu-bdr-suite-download/

Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.

5/5 - (1 vote)