Deploying to Azure with ARM Templates

Azure Resource Manager (ARM) introduces a new set of API’s that are leveraged when resources in Azure are provisioned and deployed – benefits of which the Classic Azure Service Management (ASM) API’s simply didn’t have.

The Azure Resource Manager is the portal accessed via:

With this new portal and related API’s came the concept of ‘Resource Groups’ which are a logical container used to group together Azure resources. For example, Virtual Machines, Storage Accounts, Load Balancers, Azure SQL Database (or SQL on IaaS VM), and so on. Resources that are deployed into a Resource Group should generally share the same management life-cycle.

Each of the individual resources in Azure are managed by ‘resource providers’ which are responsible for their management and configuration, and as such means that the resources can be presented via a single management pane rather than individual API’s, which wasn’t the case in the ASM model.

Prior to ARM it was necessary to deploy any dependent resources first, for example, a Storage Account was needed first in order to store the Virtual Hard Disk related to a Virtual Machine. However, ARM is smart enough to provision any resource dependencies based on the type of resource being requested, and provision them in the correct order too.

Only those dependent resources which don’t already exist are provisioned, while any which were already in existence and don’t require updating are left alone. Furthermore, if any of the resources have no direct dependencies they can be deployed in parallel, making the whole deployment faster.

Automating Deployments

One of the great benefits of using the ARM model is that it allows for resources to be described using Java Script Object Notation (JSON) templates.  These templates consist of sections: “Parameters”, “Variables”, and “Resources”.

Parameters allow for inputting values at the time of deployment – they are not absolutely required, but without them the JSON template would deploy the resources with the same parameters each time (e.g a VM, deployed as the same size as last time)

Variables allow for the construction of values which can be used in the template, typically they are based on values provided from the parameters and can simplify the template by reducing complex expressions.

The Resources section is where the resources to be deployed (or updated) are actually defined.

By making use of JSON templates it’s possible to not only declare the resource types to be deployed, but also their related configuration metrics.  Taking the example above, declare the following:

  • A Virtual Machine and it’s type/size, e.g. “D1_v2”
  • A Storage account type and size, e.g. “Standard” or “Premium” / “200Gb”
  • An Azure SQL DB and performance type, e.g. “P11”

Once the declarative document is ready and it contains all of the resources desired, it can be sent to ARM ready for provisioning.

The template may be deployed from within the ARM portal but in order for it to be scalable it’s a good idea to automate the deployment of it. This can best be achieved by uploading the JSON template to your Azure Storage Account, before using a Powershell deployment script to execute it.

Two types of deployment exist and you specify the type in the “Mode” setting of the Powershell script – incremental, or complete.

Incremental deployments are the default mode in which the following actions are taken:

  • Any resources which may already exist in the resource group specified in the template are left unchanged
  • Resources specified in the template which do not exist in the specified resource group are created
  • No changes to resources which already exist in the resource group and have changes specified in the template which match those deployed previously
  • Resources which already exist in the resource group that have updated settings in the JSON template are re-provisioned

Complete mode makes the following actions:

  • Deletes resources which exist in the resource group but are not specified in the template
  • Provisions resources specified in the template that do not exist in the resource group
  • Makes no changes to resources that exist in the resource group in the same condition defined in the template
  • Resources which already exist in the resource group that have updated settings in the JSON template are re-provisioned

By making use of ARM templates and deployment scripts, provisioning cloud resources in Azure becomes more efficient than ever. More info can be found via the links below:

Leave a Reply