Petya Petrova - Fotolia
An overview of ARM templates for Azure resource deployment
Azure Resource Manager templates streamline the way IT and development teams deploy cloud resources. To get started, grasp these key concepts around formatting, syntax and more.
Infrastructure as code transforms cloud resources into programmable objects that admins can describe, configure and deploy via code. This can speed up deployment, improve consistency, facilitate configuration reuse and provide an audit trail of changes.
Microsoft supports IaC through Azure Resource Manager (ARM) templates. To get started with these templates, users need to be familiar with the basic properties, syntax, development techniques and deployment methods.
Template format
ARM is the primary administration tool within the Azure platform. ARM templates have five core properties:
- readable descriptions of Azure resource properties and configuration, which are written in JSON syntax and can include four elements.
- parameters
- variables
- resources
- outputs
As Microsoft documentation points out, a skeleton template has the following structure, where the items in quotes are the key elements:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "",
"parameters": { },
"variables": { },
"functions": [ ],
"resources": [ ],
"outputs": { }
}
A functional template has properties within each element, for example:
"variables": {
"<variable-name>": "<variable-value>",
"<variable-object-name>": {
<variable-complex-type-value>
},
"<variable-object-name>": {
"copy": [
{
"name": "<name-of-array-property>",
"count": <number-of-iterations>,
"input": {
<properties-to-repeat>
}
}
]
}
ARM template sections
ARM template sections
According to Microsoft documentation, ARM templates are composed of the following section:
- $schema documents the URL location of the JSON schema file that describes the Azure templating language.
- contentVersion is an arbitrary number that lets users track changes to the template.
- parameters specify resource values and attributes -- such as versions, server names or deployment type -- that are used at template runtime to customize deployments.
- variables are constant values admins can use in the place of particular settings to facilitate consistency and make it easier to change multiple settings in a template. Variables are optional but improve readability and simplify the syntax of complicated functions.
- functions describe long, complicated expressions that modify template behavior and outputs in response to parameters and variables.
- resources describe a set of deployed Azure services, including their configuration and properties, which are set through parameters and variables.
- outputs contain data, such as a universal resource identifier, that is returned by a particular deployment.
There are limits to template size and complexity, but most users are unlikely to encounter them. Templates can be no larger than 1 MB, with each parameter file limited to 64 KB. A template can have up to 256 parameters and variables, as well as 64 output values.
Develop and deploy
Since ARM templates consist of nothing but JSON-formatted text, enterprises can use any text editor, preferably one with JSON format highlighting, to develop them.
One popular option is Visual Studio Code, a free, open source editor that features Microsoft's IntelliSense highlighting and autocompletion, embedded debugger and integrated git support. Developers who use Visual Studio 2017 can write templates via the tool's built-in support for Azure development.
Those who prefer to work in a web UI can develop templates in the Azure portal, which provides an editor and interface to enter parameter values and trigger deployments.
Users can also choose the no-code route and create templates via an Azure feature that exports existing resources into a template to clone them. If they deployed resources as part of a Resource Group, admins can navigate to the group in the Azure portal and select Automation Script. This causes ARM to evaluate the resources and output a template. As with all code generators, the process isn't perfect and could include errors that require cleanup.
There are numerous other ways to deploy ARM templates, including through:
- Azure CLI
- Azure PowerShell
- Azure Cloud Shell
- ARM portal
Other uses
Templates help maintain consistency across an Azure environment, particularly in hybrid or multi-cloud scenarios. Templates can also enforce role-based access controls through role assignments, such as owner, contributor or reader, to a user, group or application as a parameter.
Enterprises can also use ARM templates to automate the deployment and configuration of virtually any Azure resource -- Microsoft offers over 700 QuickStart templates to customize.