Azure Resource Manager Templates

Declaratively deploy and manage your Azure resources with infrastructure as code.

Introduction to ARM Templates

Azure Resource Manager (ARM) templates are JSON files that define the infrastructure and configuration for your Azure deployment. They allow you to declare what you want to deploy, without having to write imperative scripting code to create that deployment. ARM templates provide a reliable and consistent way to deploy resources across different environments.

Why Use ARM Templates?

  • Consistency: Ensures that your deployments are repeatable and identical every time.
  • Automation: Enables automated deployment pipelines for faster and more efficient resource provisioning.
  • Version Control: Treat your infrastructure like application code, allowing for tracking, collaboration, and rollback.
  • Declarative: Focus on the desired state of your resources, and let Azure Resource Manager handle the creation and configuration.
  • Modularity: Break down complex deployments into smaller, reusable template modules.
ARM Template Overview Diagram

Core Concepts

An ARM template is a JSON document that contains the following sections:

  • $schema: The URL to the schema file that defines the structure of the template.
  • contentVersion: A version number for the template.
  • parameters: Input values for the template.
  • variables: Intermediate values used within the template.
  • resources: The Azure resources to be deployed.
  • outputs: Values returned after deployment.

Example Template Structure


{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageAccountName": {
      "type": "string",
      "metadata": {
        "description": "Name of the storage account."
      }
    }
  },
  "variables": {
    "location": "[resourceGroup().location]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2021-04-01",
      "name": "[parameters('storageAccountName')]",
      "location": "[variables('location')]",
      "sku": {
        "name": "Standard_LRS"
      },
      "kind": "StorageV2"
    }
  ],
  "outputs": {
    "storageAccountID": {
      "type": "string",
      "value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
    }
  }
}
                    

Deploying ARM Templates

You can deploy ARM templates using various tools, including:

  • Azure portal: Upload the template and configure parameters.
  • Azure CLI: Use commands like az deployment group create.
  • Azure PowerShell: Use cmdlets like New-AzResourceGroupDeployment.
  • REST API: Programmatically deploy templates.
  • SDKs: Integrate deployments into your applications.

Azure CLI Example


az deployment group create \
  --resource-group myResourceGroup \
  --template-file <path-to-your-template.json> \
  --parameters storageAccountName=mystorageaccountunique
                    

Azure PowerShell Example


New-AzResourceGroupDeployment `
  -ResourceGroupName "myResourceGroup" `
  -TemplateFile "" `
  -storageAccountName "mystorageaccountunique"
                    

Advanced Concepts

Linked Templates and Template Functions

ARM templates support linked templates for modularity and reuse. You can also leverage built-in template functions for dynamic value generation, string manipulation, and referencing resource properties.

Deployment Stacks (Preview)

For managing resource lifecycle across your Azure organization, consider exploring Deployment Stacks, a new approach for managing resources declaratively.

Further Learning

Explore the official Azure documentation for in-depth guides, tutorials, and API references: