Automate Infrastructure with Azure ARM Templates – Part-1

In this Blog , we will see how we can automate infrastructure deployment with Azure ARM templates . Before going into deep dive let’s look into some basics of ARM Templates and some pre-requisite tools for deploying the infrastructure with ARM Templates .

What is ARM () Templates ?
Azure ARM Templates is one of the cloud native Infra as code tool to deploy infrastructure. You can define your cloud resources into json files.Then you deploy the files to the Cloud by running either Azure-CLI or PowerShell. Every JSON file is known as a template. A template contains your resources you want to deploy but it also contains different constructs that makes it easy to manage your resources as things gets more complicated. Examples of such constructs are parameters, variables, template functions and outputs.

The simplest way to get started with ARM templates is to understand the basic elements of the json file.

$schema – This element identifies the version of template language to be used. The value of this element changes based on the type of editor and the scope of the deployment. There are four different scopes as given below at which you can deploy an ARM template.

1- Subscription Scope When you need to deploy resources at the subscription level, Let’s take a example to create resource groups or provision policies and resource-based access controls, you need to use subscription level deployments. For this type of deployments, the value of $schema should be https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#

2- Management Group Scope Management groups in Azure are used to organise subscriptions for better governance. When you need to provision resources such as policies at the management group level, you need to the use the management group level schema. For this type of deployments, The value of this element for management group level deployments should be https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#.

3-Tenant Scope For provisioning resources across multiple Azure AD tenants, you need the tenant scoped deployments. For tenant level deployments the value of $schema element should be set to https://schema.management.azure.com/schemas/2019-08-01/tenantDeploymentTemplate.json#.

4- Resource Group Scope This is the default type of deployment you see when start writing ARM Templates. When using this deployment scope, you describe resources that need to be deployed within a given resource group in a subscription. The value of $schema for this type of deployments in VS Code should be https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#. For Visual Studio, this value should be https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#.

ContentVersion It identifies the version of the template content. This value is required but can be set to anything you want. If you use source control for ARM templates, you can increment the value of this element in your template at every commit.

Parameters This element accepts a set of parameters that act as input to the ARM template deployment using which you can introduce reusability of ARM templates. If you are familiar with any programming language, similar to a function or a method parameters, ARM template parameters too support different data types, valid values, default values, and different other characteristics such as min and max values (for numeric types), and min and max length (for string types). This is not a mandatory element but highly recommended to parameterise the template.

Functions ARM template syntax support built-in functions and expressions. These functions range from comparison functions to numeric, date, string, and so on. In a later update to the ARM template syntax, support for custom user-defined functions was added. You can now define some complex expressions that you want to use in the template as user-defined functions. This is not a mandatory element.

Variables Variables, similar to functions, can help reduce the complexity of expressions in the ARM template. This is not a mandatory element. In an ARM template, variables are predominantly inside expressions. Between parameters and variables, you need to always a maintain either free-form or known configuration to create templates are easy to deploy.

Resources This element is where you define what Azure resource you need to deploy or update. An ARM template must have at least one resource. The type of valid resources supported in a template depends on the value of $schema element.

Outputs Using this element, you can specify the values returned by the template after the deployment is complete. This element is not mandatory. This can be very useful when using nested templates and you will learn more about it soon in this series.

In next part , We will create our first ARM Template and deploy to Microsoft Azure.

Leave a Reply

Your email address will not be published. Required fields are marked *