Skip to main content

Understanding Declarative ARM Template Deployments

Write, validate, preview, and deploy a parameterized ARM template for a storage account, then reuse it to build identical environments on demand.

Overview and What You Will Learn

An ARM template is a JSON file that describes the Azure resources you want, and Azure Resource Manager works out how to create or update them to match. In this lab you write a real template for a storage account, validate it, preview the changes with what-if, deploy it, and reuse it with different parameter files to build two environments from one definition.

By the end you will be able to:

  • Read and write the five sections of an ARM template
  • Separate environment differences into parameter files
  • Run validate and what-if before every deployment
  • Explain why re-running a template does not create duplicates
  • Choose between Incremental and Complete deployment modes without deleting things by accident

Why This Matters in Production

Infrastructure that exists only as a series of portal clicks cannot be reviewed, repeated, or recovered reliably. If a resource group is deleted or a new region is needed, the team rebuilds from memory and an out-of-date wiki page, and the copy never quite matches the original.

A template turns that into a file in version control. A platform team at a company like Atlassian can review an infrastructure change in a pull request, preview it with what-if, and deploy the same definition to dev, test, and production, so the environments differ only by parameter values.

Core Principles

ARM templates are declarative: you describe the end state and Azure decides the steps and the order. An imperative script says "create a VNet, then a subnet, then a VM". A template says "this VNet, subnet, and VM should exist", and ARM handles dependencies, retries, and updates.

A template has up to five sections:

  • parameters: Values you supply at deploy time, such as names, regions, and SKUs.
  • variables: Values computed once inside the template.
  • resources: The Azure resources to create or update.
  • outputs: Values returned after deployment, such as an endpoint URL.
  • functions: Optional reusable expressions, for advanced templates.

Anything wrapped in square brackets, such as [parameters('location')], is an expression that ARM evaluates at deployment time.

flowchart TD T["Template plus
parameter file"]:::person -->|validate| V["ARM validation"]:::tool V -->|what-if| W["Change preview"]:::app W -->|deploy| D["Deployment"]:::tool D -->|creates or updates| R[("Azure resources")]:::cloud classDef person fill:#EDE9FE,color:#1E293B classDef tool fill:#326CE5,color:#FFFFFF classDef app fill:#FFEDD5,color:#1E293B classDef cloud fill:#D1FAE5,color:#1E293B

Because the template states the desired result, deployments are idempotent. Running the same template again updates anything that drifted and leaves everything else alone.

Remember

Bicep is a friendlier language that compiles to ARM templates, and it is the recommended way to author new infrastructure. Learning the ARM structure first makes Bicep easy, because the sections and concepts are identical.

Detailed Step-by-Step Practical Lab

Step 1: Create a resource group.

Bash
RG=rg-arm-lab-mumbai
az group create --name $RG --location centralindia

Step 2: Write the template. Save this as storage-template.json. It takes a name, a region, a SKU, and an environment tag, and it turns on secure defaults for the account. JSON templates cannot contain ordinary comments, so the explanation is below the block.

JSON
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": {
"type": "string",
"minLength": 3,
"maxLength": 24,
"metadata": { "description": "Globally unique name, lowercase letters and digits only" }
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
},
"skuName": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": ["Standard_LRS", "Standard_GRS", "Standard_ZRS"]
},
"environment": {
"type": "string",
"defaultValue": "dev"
}
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2023-01-01",
"name": "[parameters('storageAccountName')]",
"location": "[parameters('location')]",
"sku": { "name": "[parameters('skuName')]" },
"kind": "StorageV2",
"tags": { "environment": "[parameters('environment')]" },
"properties": {
"minimumTlsVersion": "TLS1_2",
"allowBlobPublicAccess": false,
"supportsHttpsTrafficOnly": true
}
}
],
"outputs": {
"blobEndpoint": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))).primaryEndpoints.blob]"
},
"storageAccountId": {
"type": "string",
"value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
}
}
}

Reading the template: the location parameter defaults to the resource group's region, allowedValues rejects any SKU you did not approve, and minLength and maxLength catch an invalid account name before deployment starts. The properties block disables anonymous blob access and old TLS versions for every account built from this file.

Step 3: Write one parameter file per environment. Storage account names are globally unique, so change the suffix if a name is taken.

JSON
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": { "value": "stdevlabrahul01" },
"skuName": { "value": "Standard_LRS" },
"environment": { "value": "dev" }
}
}

Save that as dev.parameters.json. Then create prod.parameters.json with the same structure but these values: name stprodlabrahul01, SKU Standard_GRS, environment prod.

Step 4: Validate the template. Validation checks syntax, parameter rules, and basic resource definitions without creating anything.

Bash
az deployment group validate \
--resource-group $RG \
--template-file storage-template.json \
--parameters @dev.parameters.json

Step 5: Preview the change with what-if. What-if compares the template with what exists now and lists each resource as create, modify, delete, or no change.

Bash
az deployment group what-if \
--resource-group $RG \
--template-file storage-template.json \
--parameters @dev.parameters.json

Step 6: Deploy the dev environment.

Bash
az deployment group create \
--name dev-storage \
--resource-group $RG \
--template-file storage-template.json \
--parameters @dev.parameters.json

Step 7: Prove idempotency. Run what-if again against the same parameters. Nothing should change, because the resource already matches the template.

Bash
az deployment group what-if \
--resource-group $RG \
--template-file storage-template.json \
--parameters @dev.parameters.json

Step 8: Reuse the same template for production. Only the parameter file changes, yet the result is a second account with geo-redundant storage and a different tag.

Bash
az deployment group create \
--name prod-storage \
--resource-group $RG \
--template-file storage-template.json \
--parameters @prod.parameters.json
az storage account list --resource-group $RG \
--query "[].{name:name, sku:sku.name, env:tags.environment}" --output table

Step 9: Read the outputs.

Bash
az deployment group show --resource-group $RG --name dev-storage \
--query properties.outputs

Step 10: See why Complete mode is dangerous. Incremental mode, the default, leaves resources that are not in the template alone. Complete mode removes them. Run only a what-if, and notice that the production account is marked for deletion because the dev parameters do not mention it.

Bash
az deployment group what-if \
--resource-group $RG \
--template-file storage-template.json \
--parameters @dev.parameters.json \
--mode Complete

Step 11: Look at the Bicep equivalent. Decompiling shows how the same definition reads in Bicep.

Bash
az bicep decompile --file storage-template.json

Step 12: Clean up.

Bash
az group delete --name $RG --yes --no-wait

Production Best Practices & Common Pitfalls

  • Keep templates and parameter files in version control: A template on one laptop is as fragile as the portal clicking it replaced. Review changes through pull requests.
  • Run validate and what-if in your pipeline: Make the what-if output part of the review so reviewers see exactly what will change before approval.
  • One template, many parameter files: Environments should differ only in parameter values, never in the template itself.
  • Never put secrets in parameters or outputs: Deployment history stores them. Use securestring parameters or Azure Key Vault references, and never output a secret.
  • Use explicit dependsOn only when needed: ARM infers dependencies from resource references. Add dependsOn when two resources are related but one does not reference the other.
  • Protect important resources: Add resource locks, and keep the apiVersion values current as services evolve.
  • Prefer Bicep for new work: It compiles to the same ARM template, with less syntax and better tooling support.
Common Mistake

Deploying to a shared resource group in Complete mode. Every resource that is not in the template is deleted, including things other teams created. Use Incremental unless you have read the what-if output and want the cleanup.

Common Mistake

Hard-coding a region, such as centralindia, inside the resources section. The template then cannot be reused for another region without editing it. Use a location parameter instead.

Security

Anything returned in outputs is visible in the deployment history to anyone who can read it. Output resource IDs and endpoints, never keys or connection strings.

Tip

Storage account names must be globally unique. Build them with uniqueString(resourceGroup().id) in a variable if you want names that never collide.

Quick Reference & Troubleshooting Commands

Command Description
az deployment group validate Check a template without deploying
az deployment group what-if Preview creates, changes, and deletes
az deployment group create Deploy a template to a resource group
az deployment group list List past deployments in a resource group
az deployment operation group list Show per-resource status for a deployment
az deployment group export Export a resource group as a template
az bicep build Compile a Bicep file to an ARM template
az bicep decompile Convert an ARM template to Bicep
Error Likely cause
StorageAccountAlreadyTaken The name is not globally unique
InvalidTemplate Syntax error or a wrong function in an expression
RequestDisallowedByPolicy An Azure Policy denied the resource
ResourceNotFound during deploy A missing dependency, so add a reference or dependsOn

Explore More in Azure Fundamentals and Governance

All 6 Topics

Frequently Asked Questions

Is Understanding Declarative ARM Template Deployments free to learn on DevOps Network?

Yes - this topic, like everything on DevOps Network, is 100% free with no paywall or sign-up gate.

What does the Understanding Declarative ARM Template Deployments topic cover?

Write, validate, preview, and deploy a parameterized ARM template for a storage account, then reuse it to build identical environments on demand.

Found a mistake, an outdated step or a broken link?