Templates overview - Azure Resource Manager (original) (raw)

With the move to the cloud, many teams adopted agile development methods. These teams iterate quickly. They need to repeatedly deploy their solutions to the cloud, and know their infrastructure is in a reliable state. As infrastructure became part of the iterative process, the division between operations and development disappeared. Teams need to manage infrastructure and application code through a unified process.

To meet these challenges, automate deployments and use the practice of infrastructure as code. In code, you define the infrastructure that needs to be deployed. The infrastructure code is part of your project. Just like application code, store the infrastructure code in a source repository and version it. Anyone on your team can run the code and deploy similar environments.

To implement infrastructure as code for your Azure solutions, use Azure Resource Manager templates (ARM templates). The template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it. In the template, you specify the resources to deploy and the properties for those resources. You can also specify in which resource group those resources are deployed.

Tip

We introduced a new language named Bicep that offers the same capabilities as ARM templates but with a syntax that's easier to use. Each Bicep file is automatically converted to an ARM template during deployment. If you're considering infrastructure as code options, we recommend looking at Bicep. For more information, see What is Bicep?.

Why choose ARM templates?

If you're trying to decide between using ARM templates and one of the other infrastructure as code services, consider the following advantages of using templates:

{  
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",  
  "contentVersion": "1.0.0.0",  
  "parameters": {  
    "location": {  
      "type": "string",  
      "defaultValue": "[resourceGroup().location]"  
    }  
  },  
  "resources": {  
    "mystore": {  
      "type": "Microsoft.Storage/storageAccounts",  
      "apiVersion": "2023-04-01",  
      "name": "mystorageaccount",  
      "location": "[parameters('location')]",  
      "sku": {  
        "name": "Standard_LRS"  
      },  
      "kind": "StorageV2"  
    }  
  }  
}  

Template file

Within your template, you can write template expressions that extend the capabilities of JSON. These expressions use the functions that Resource Manager provides.

The template has the following sections:

Template deployment process

When you deploy a template, Resource Manager converts the template into REST API operations. For example, when Resource Manager receives a template with the following resource definition:

"resources": [
  {
    "type": "Microsoft.Storage/storageAccounts",
    "apiVersion": "2022-09-01",
    "name": "mystorageaccount",
    "location": "centralus",
    "sku": {
      "name": "Standard_LRS"
    },
    "kind": "StorageV2"
  },
]

It converts the definition to the following REST API operation, which it sends to the Microsoft.Storage resource provider:

PUT
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/mystorageaccount?api-version=2022-09-01
REQUEST BODY
{
  "location": "centralus",
  "sku": {
    "name": "Standard_LRS"
  },
  "kind": "StorageV2",
  "properties": {}
}

Notice that the apiVersion you set in the template for the resource is used as the API version for the REST operation. You can repeatedly deploy the template and have confidence it continues to work. By using the same API version, you don't have to worry about breaking changes that might be introduced in later versions.

To deploy a template, use any of the following options:

Template design

Define templates and resource groups based on how you want to manage your solution. For example, you can deploy your three-tier application through a single template to a single resource group.

Diagram that shows a three-tier application deployment using a single template.

You don't have to define your entire infrastructure in a single template. Often, it makes sense to divide your deployment requirements into a set of targeted, purpose-specific templates. You can easily reuse these templates for different solutions. To deploy a particular solution, create a main template that links all the required templates. The following image shows how to deploy a three-tier solution through a parent template that includes three nested templates.

Diagram that shows a three-tier application deployment using nested templates.

If you envision your tiers having separate lifecycles, you can deploy your three tiers to separate resource groups. The resources can still be linked to resources in other resource groups.

Diagram that shows a three-tier application deployment with separate resource groups.

For information about nested templates, see Using linked templates with Azure Resource Manager.

After creating your template, you might want to share it with other users in your organization. Template specs enable you to store a template as a resource type. Use role-based access control to manage access to the template spec. Users with read access to the template spec can deploy it, but not change the template.

This approach means you can safely share templates that meet your organization's standards.

Get support

Here are the steps for opening a support ticket for Azure Resource Manager (ARM) template related issues:

  1. Open the Azure portal.
  2. Select the Support + Troubleshooting icon from the upper right corner.
  3. In Briefly describe the issue, enter ARM template, and then select Go.
  4. In Which service are you having an issue with?, select Portal under Monitoring & Management, and then select Next.
  5. Select a subscription, and then select Next.
  6. Select Issue with ARM templates, and then select Next.
    Screenshot of requesting ARM template support.

Next steps