Azure ARM Templates: Declarative, Idempotent Deployments
You will deploy Azure resources from a parameterized ARM template and preview changes with what-if before applying. By the end you will run repeatable, idempotent deployments instead of one-off portal clicks.
Learning Objectives
- Author an ARM template with parameters.
- Preview changes with the what-if operation.
- Deploy idempotently and confirm no drift on re-run.
- Time: ~3 hours · Difficulty: Intermediate · Prereqs: the Azure CLI and a resource group.
Architecture Overview
graph LR
T[template.json + parameters] -->|az deployment| ARM[Azure Resource Manager]
ARM -->|what-if preview| Diff[Change set]
ARM -->|create| Res[Resources]
Environment Setup
You will need: the Azure CLI and a target resource group.
Before you begin: always run what-if before deploying to production scopes.
Step-by-Step Execution
01
Write a parameterized template
# template.json (excerpt)
"parameters": { "saName": { "type": "string" } },
"resources": [{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2023-01-01",
"name": "[parameters('saName')]",
"location": "[resourceGroup().location]",
"sku": { "name": "Standard_LRS" },
"kind": "StorageV2"
}]
02
Preview with what-if
what-if shows exactly what will change before anything is created or modified.
az deployment group what-if -g tyf-rg --template-file template.json --parameters saName=tyfstore0103
Deploy
$ az deployment group create -g tyf-rg --template-file template.json --parameters saName=tyfstore01
"provisioningState": "Succeeded"
Progress So Far
graph LR
A[01 Template] -->|done| B[02 what-if]
B -->|done| C[03 Deploy]
style A fill:#1a4a1a,stroke:#00ff00,color:#fff
style B fill:#1a4a1a,stroke:#00ff00,color:#fff
style C fill:#1a4a1a,stroke:#00ff00,color:#fff
Testing & Validation
az deployment group what-if -g tyf-rg --template-file template.json --parameters saName=tyfstore01Re-running what-if after a successful deploy should report no changes, proving the template is idempotent.
Troubleshooting
- Name already taken: storage account names are globally unique; choose another.
- Validation failed: run
az deployment group validateto see the schema error. - Unexpected what-if changes: a property drifted in the portal; let the template be the source of truth.
Extension Ideas
- Move to the cleaner Bicep syntax in Infrastructure as Code.
- Deploy from a pipeline with GitHub Actions.
- Audit deployed resources with CSPM.
Key Results
- Deployed resources declaratively from a parameterized template.
- Previewed every change with what-if before applying.
- Confirmed idempotency: a re-run reported no changes.
- Replaced manual portal steps with repeatable deployments.