COMPONENTS OF AN ARM TEMPLATE | BENEFITS OF ARM TEMPLATES

Benefits of using Azure Resource Manager

  • It is template driven. You can use ready templates to deploy all your resources.
  • It is multi-service. This means that you can deploy, manage and monitor all the resources for your solution as a group rather than having to handle these resources individually which is tedious.
  • It is idempotent. This means that you can deploy your solution over and over again without affecting the current state of resources along with the guarantee that your resources are deployed in a consistent state.
  • It is declarative. Hence, it allows you to declare which resources you want to have and manage those resources only rather than having to work with an imperative system where you have to make the rules and write the scripts.
  • It also allows you to define dependencies between resources so you can control the order in which they are deployed.
  • It is a multi-region tool that lets you choose which region you want to deploy the resources in.
  • It also gives you the benefit of access control and tags which let you control all the services and logically organize them as you see fit.

Basic Structure of an ARM Template

An ARM template contains the following elements:

schema: The schema defines the basic layout of the template.

contentVersion: It specifies the version.

parameters: These are the values that are needed for deployment.

variables: These are the custom variables that we create within the template resource.

resources: These are one of the components of an Azure ARM template.

output: This is what you use to return data and objects from a deployment.

Now we will take a closer look at each of these elements.

Schema: The schema is a mandatory part of an ARM template and it primarily provides a layout to the Azure ARM template. A template schema of components in the ARM template defines how the template is going to be designed or defined. Its value must be the location of the JSON schema file for the ARM template language. This JSON schema is what is used to find the right set of properties for resources, features, etc. Taking an example of Virtual Machines – as you know that Azure releases new features every day and in a template that is already deployed, how can you make sure that it’s always up to date with the latest features without having to manually check it yourself? This is where the schema comes in. It ensures that the Azure ARM templates are deployed with the modified schema with the new property and extension with every template. Schema points to a URL from Microsoft in which there is a definition file of the whole ARM template and how it should be formatted.

Content Version: This is another mandatory element that you can use to specify the version of the template that you are creating as part of the template that you are creating. As a part of the Azure ARM authoring process, you can use this value for convenience and tracking. It is a good practice to use the source control and build in a process to auto update the content version element value each time you make updates. This avoids you having to manually enter a version number each and every time.

Parameters: You can think of parameters as parameters in any other programming language. They are used to provide flexibility within a function and ARM parameters work the same way. They are values that you define to give yourself the ability to collect user input for resource properties before starting the deployment. For instance, parameters can be the VM’s name or the username and password which must be unique for every user. There are multiple properties within parameters and you can have minimum and maximum values for different parameters.

Variables: These are also similar to how variables are used in other programming languages. They help you simplify the template language. You can use the variable elements to store values for different resource properties and reuse them as needed instead of having to rewrite them again and again. The Azure ARM allows you to construct variable values at runtime. Variable values in ARM templates can have standard type values and complex type values. However, variables are not mandatory.

Resources: It is one of the key components of the Azure ARM templates. It is a mandatory element and it defines a collection of resources that you want to deploy as part of the Azure ARM template. For every resource you specify, you also need to define some standard sub elements like name, type, API version, location, properties, etc. The properties are used to describe resource specific properties and its values depend on the type of resource.

Output: The output of the ARM template is used to return data and objects from a deployed ARM template. For instance, once a VM is deployed, the VM name is generate and you may want this VM name to be published. So, to do this, you add it to the output. In cases where you have nested template deployment, outputs can be used to share states and data between multiple templates. The output element can also be used for debugging.