Sikau

Microsoft Azure · Day 9 · about 45 min

ARM templates and Bicep

Declarative, idempotent deployments in the right order.

Click, click, forget

Asha built the shop's test environment by clicking through the portal for an afternoon. Now Sita wants an identical production copy — and nobody remembers which boxes were ticked. Clicking doesn't scale, can't be reviewed, and can't be repeated exactly.

Infrastructure as code fixes that: describe the resources in a file, keep it in Git, and let Azure Resource Manager make reality match. Azure's native formats are ARM templates (JSON) and Bicep, a cleaner language that compiles to the same JSON. Terraform and Pulumi work too, through the same ARM API.

Declarative and idempotent

A template is declarative: it says what should exist, not the steps to create it. ARM works out the order and the API calls. Deployments are idempotent: deploy the same template twice and the second run changes nothing. Change one property and only that resource is updated.

param location string = 'centralindia'
@allowed(['Standard_LRS', 'Standard_ZRS'])
param sku string = 'Standard_LRS'

resource photos 'Microsoft.Storage/storageAccounts@2023-05-01' = {
  name: 'momophotos'
  location: location
  sku: { name: sku }
  kind: 'StorageV2'
}
  • Parameters make one template work for dev and prod; missing, unknown or disallowed values fail before anything is deployed.
  • Dependencies: ARM deploys in parallel where it can, but a resource waits for everything in its dependsOn. Bicep adds these for you when one resource references another.
  • Circular dependencies are an error.
  • What-if (az deployment group what-if) previews creates, updates and deletes before you deploy.

The rest of this lesson

  • Incremental and Complete modesexplain
  • Which goes first?predict
  • Deployment wordsmatch
  • One deploymentorder
  • Deploy a templatewrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 10 lessons of Microsoft Azure