Compute · Lesson 13 of 24

ARM templates and Bicep

Writing down what you want instead of clicking it, so the same environment can be rebuilt in one command.

About 10 min · Interactive · 3 practice questions

Exam objective
Interpret an ARM template or Bicep file · Modify an existing template/file · Deploy resources · Export a deployment as a template or convert to BicepDeploy and manage Azure compute resources · 20–25% of the exam · typical question: Read a template snippet and answer "what does line X do / what is missing", Complete vs Incremental mode
In one sentence. Instead of clicking through a wizard every time, you write the answers to the wizard in a text file and hand the file to Azure. Azure reads the file, compares it with what exists, and builds whatever is missing. ARM JSON is the older, verbose format; Bicep is a tidier language that turns into the same JSON. The exam shows you a file and asks what it does or what is wrong.
main.biceptext file on your PCaz deployment group createsends the file to ARMResource Managercompares wanted vs realcreates missingleaves matching
Declarative: you describe the end state, Azure works out the steps. Run it twice and nothing breaks.

Reading a template

ARM JSON sectionBicep keywordPlain meaning
parametersparamQuestions answered at deploy time (name, size). defaultValue makes one optional; allowedValues limits choices.
variablesvarValues worked out inside the file (a name built from a prefix)
resourcesresourceThe things to build: type, apiVersion, name, location, properties
dependsOnusually not neededBuild order. In Bicep, referring to another resource by its symbolic name sets the order automatically.
outputsoutputValues returned when done (an IP address, a connection string)
[resourceGroup().location]resourceGroup().locationFunctions; JSON wraps them in square brackets
// main.bicep
param location string = resourceGroup().location   // optional, has a default
param storageName string                            // required, no default

resource sa 'Microsoft.Storage/storageAccounts@2023-01-01' = {
  name: storageName
  location: location
  sku: { name: 'Standard_LRS' }
  kind: 'StorageV2'
}

output blobEndpoint string = sa.properties.primaryEndpoints.blob

You, the admin: four ways to get and use a template

  1. From a wizard: on the Review + create tab click Download a template for automation. You get the JSON and a parameters file instead of clicking Create.
  2. From an existing thing: Resource group › Automation › Export template. Verbose, but a start. Convert to Bicep with az bicep decompile -f template.json.
  3. From a past run: Resource group › Deployments › pick one › Template.
  4. Deploy: Home › search "Deploy a custom template" › Build your own template in the editor, or az deployment group create -g RG1 -f main.bicep -p storageName=contoso01, or New-AzResourceGroupDeployment -ResourceGroupName RG1 -TemplateFile main.bicep. Deployment scopes also exist for subscription, management group and tenant level (az deployment sub create etc.).

Two settings that matter

  • Mode Incremental (default): add what is missing, update what differs, ignore everything else in the group.
  • Mode Complete: make the group look exactly like the file. Anything in the group that is not in the file is deleted. Dangerous; the exam loves it.

A failed deployment does not undo what it already built; read the error under Deployments, fix the file, run again (idempotent, so already-correct resources are untouched). --what-if previews changes without applying them. Parameter files (main.parameters.json or main.bicepparam) let one template serve dev and prod.

Trap wording. "After deployment, resources disappeared" = Complete mode. "Deployment fails asking for a value" = a parameter with no default. "Which section holds the storage account?" = resources. "Ensure the VM is created after the NIC" in Bicep = reference the NIC's symbolic name, not a manual dependsOn.

Key points

  • A template is the wizard's answers in a file. Azure builds what is missing and leaves what matches (idempotent).
  • Sections: parameters (inputs), variables (computed), resources (what to build), outputs (returned values). Bicep: param, var, resource, output.
  • Complete mode deletes anything in the group not in the file; Incremental (default) does not.
  • Get a template from a wizard's Review tab, Export template on a resource group, or the Deployments blade; az bicep decompile turns JSON into Bicep.

Formal terms: Declarative, idempotent, ARM template, Bicep, parameter file, deployment mode, symbolic name, module, what-if, decompile.

Check your understanding

3 exam-style questions in the formats AZ-104 uses. Each is marked when you check it, with the reasoning.

0 of 3 checked

All scenarios and questions are original. None are taken from the exam, Microsoft's practice assessment or any question bank. PrepToExcel is not affiliated with Microsoft.