ARM Templates & Bicep
read a template · modes · loops · dependencies · what-if · export and convert
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Reading a Bicep file
| Snippet | What it means |
|---|---|
targetScope = 'subscription' | Deployment scope. Allowed values: resourceGroup (the default, no need to set it), subscription, managementGroup, tenant. A module can use a different scope. |
param storagePrefix string | A parameter with no default value: it must be supplied. |
param storageSKU string = 'Standard_LRS' | A parameter with a default value. |
@secure() on a param | The value is not saved to deployment history and is not logged. ARM equivalent: securestring / secureObject. |
var name = '${prefix}${uniqueString(resourceGroup().id)}' | A variable: computed inside the file. A param is supplied at deployment time. |
resource stg 'Microsoft.Storage/storageAccounts@2025-06-01' = {…} | Declares a resource. stg is its symbolic name. |
resource dns '…' = if (deployZone) {…} | Conditional deployment. ARM JSON uses "condition": true. |
[for i in range(0, 5): {…}] | Loop. Also [for item in array: {…}], [for (item, i) in array: {…}] and [for x in items(object): {…}]. Each instance needs a unique name. Max 800 iterations, never negative. |
@batchSize(2) above a loop | Deploys 2 instances at a time. Loops run in parallel by default; @batchSize(1) is fully sequential. |
dependsOn: [ dns ] | Explicit dependency. Rarely needed. |
existing keyword | Declares a resource to read, not to deploy. |
module m './file.bicep' = { name: '…', params: {…} } | Calls a module. Read its outputs as m.outputs.x. |
output storageEndpoint object = stg.properties.primaryEndpoints | An output. |
- Bicep is declarative: the order of elements in the file does not affect how the deployment is processed.
- Bicep creates an implicit dependency when one resource references another by symbolic name (for example
exampleDnsZone.properties.nameServers), and when a resource is nested or usesparent:. When an implicit dependency exists, do not add an explicit one. UnnecessarydependsOnslows deployment because resources cannot deploy in parallel. - Resources with no dependency between them deploy in parallel.
- Bicep parameter files (
.bicepparam) need Azure CLI 2.53.0+ and Bicep CLI 0.22+. With a.bicepparamfile, do not pass--template-file. - Azure CLI cannot deploy a remote Bicep file: build it to JSON and host that.
- The deployment name defaults to the Bicep file name (
main.bicepbecomesmain). Reusing a name replaces the earlier history entry.
ARM JSON template
- Required top-level elements:
$schema,contentVersion,resources. Optional: languageVersion, apiProfile, definitions, parameters, variables, functions, outputs. - Required properties on a resource:
type,apiVersion,name.locationis required for most types but not all (role assignments do not need it). - Parameter types: string, securestring, int, bool, object, secureObject, array.
- The
$schemaURL depends on scope: resource group2019-04-01/deploymentTemplate.json, subscription2018-05-01/subscriptionDeploymentTemplate.json, management group2019-08-01/managementGroupDeploymentTemplate.json, tenant2019-08-01/tenantDeploymentTemplate.json. - Loops use
copy:name,count,mode(serial or parallel, default parallel) andbatchSize. In ARM,batchSizecannot exceedcount. copyIndex()is zero-based.copyIndex(1)offsets by 1.- You cannot loop a nested child resource in ARM. Define it as a top-level resource with type
ns/parent/childand nameparent/child. - Child resources in ARM JSON: the dependency on the parent is not implied. Define it explicitly with
dependsOn. - Only list in
dependsOnresources deployed in the same template. Resources not in the template must already exist. - Condition:
"condition": true/falseon the resource.
Deployment modes
| Incremental (default) | Complete | |
|---|---|---|
| Resources in the group that are not in the template | Left unchanged | Deleted |
| RG has A, B, C; template has A, B, D | A, B, C, D | A, B, D (C deleted) |
| Where it works | Everywhere | Root-level templates only (linked and nested templates must be incremental). Not subscription-level deployments. Not the portal. A locked resource group is not emptied. Only the RG named in the command is eligible for deletion. |
- In incremental mode, redeploying an existing resource reapplies all properties. Properties omitted from the template are reset to defaults: it is not a partial update.
- Define subnets in the
subnetsproperty of the virtual network, not as separate child resources, so redeploying the vnet does not lose them. - Changing the location or type of an existing resource makes the deployment fail. Deploy a new resource instead.
- Microsoft says complete mode is not recommended and will be gradually deprecated. Use deployment stacks for deleting resources.
Preview, export and convert
| Task | How | Notes |
|---|---|---|
| Preview a deployment | What-if | Works for RG, subscription, management group and tenant deployments. Change types: Create, Delete (complete mode only), Ignore, NoChange, NoEffect, Modify, Deploy. It cannot resolve reference, so it reports those properties as changing. |
| Export current state (portal) | From the resource group or resource | Autogenerated snapshot of the current state. Includes manual changes made after deployment. Mostly hard-coded values; usually needs clean-up. |
| Export the original template (portal) | Resource group › Deployments › pick a deployment › Template (Save from history) | Exact copy of the template used, ARM JSON only, includes parameters, ready to redeploy. Excludes later manual changes. |
| ARM JSON to Bicep | az bicep decompile --file main.json | Creates main.bicep next to the file. --force overwrites. Best-effort: output may need fixes. |
| Bicep to ARM JSON | az bicep build --file main.bicep | Produces functionally equivalent JSON. |
- Portal export is not guaranteed to succeed. A resource group with more than 200 resources cannot be exported. Some password parameters can be missing. Data Factory is not supported. Classic resources must be migrated first.
- Template and Bicep deployments need write access on the resources being deployed and
Microsoft.Resources/deployments/*. What-if has the same requirement.
Limits
| Item | Value |
|---|---|
| Parameters per template | 256 |
| Variables per template | 256 |
| Resources per template | 800 |
| Outputs per template | 64 |
| Loop or copy iterations | 800, never negative |
| Resources in an RG for portal export | 200 |
| Minimum Azure CLI for Bicep deployment | 2.20.0 |
CLI and PowerShell
| Task | Azure CLI | PowerShell |
|---|---|---|
| Deploy to a resource group | az deployment group create -g <rg> --template-file main.bicep --parameters storageAccountType=Standard_GRS | New-AzResourceGroupDeployment -ResourceGroupName <rg> -TemplateFile main.bicep |
| Deploy to a subscription | az deployment sub create --location <loc> --template-file main.bicep | New-AzSubscriptionDeployment |
| Deploy to a management group or tenant | az deployment mg create / az deployment tenant create (both need --location) | |
| Complete mode | az deployment group create --mode Complete … | New-AzResourceGroupDeployment -Mode Complete … |
| Preview (what-if) | az deployment group what-if …, or --confirm-with-what-if / -c | New-AzResourceGroupDeployment -Whatif or -Confirm |
| Bicep parameter file | az deployment group create -g <rg> --parameters storage.bicepparam | |
| ARM to Bicep | az bicep decompile --file main.json | bicep decompile main.json |
| Bicep to ARM | az bicep build --file main.bicep | bicep build main.bicep |
| Export an RG template | az group export --name <rg> | Export-AzResourceGroup -ResourceGroupName <rg> -Path ./main.json |
Only az deployment group takes --resource-group. The sub, mg and tenant versions take --location.
Exam Tips
Tick each tip once you can answer it without looking.
“Redeploy the template without deleting resources that are not in it” → Incremental mode (the default). Trap: Complete mode deletes unlisted resources.
“Make the resource group match the template exactly, removing extras” → Complete mode (--mode Complete). Trap: incremental leaves the extras in place.
“RG has A, B, C; template has A, B, D; incremental deployment” → A, B, C and D. Trap: assuming C is removed.
“Deploy in complete mode from the portal” → Not supported: use the CLI or PowerShell. Trap: looking for a portal option.
“Preview what a deployment will change” → What-if (az deployment group what-if). Trap: exporting a template shows the current state, not planned changes.
“Convert an existing ARM JSON template to Bicep” → az bicep decompile --file main.json. Trap: az bicep build goes the other way, Bicep to JSON.
“Need the exact template that created the resources, ready to redeploy” → Export from the deployment history. Trap: exporting the resource group gives an autogenerated snapshot that needs clean-up.
“Capture manual changes made after deployment into a template” → Export from the resource group or resource. Trap: the history template excludes later changes.
“Export a resource group with 250 resources” → Fails: the limit is 200 resources, so export a subset.
“Create 5 storage accounts in Bicep” → A [for i in range(0, 5): {…}] loop with a unique name per instance. Trap: giving every instance the same name.
“Deploy loop instances two at a time” → @batchSize(2) (ARM: copy mode serial, batchSize 2). Trap: the default is parallel, and batchSize 1 is fully sequential.
“ARM copyIndex() for the first instance” → 0 (zero-based). Trap: 1.
“Resource B reads a property of resource A by symbolic name” → Implicit dependency: no dependsOn needed. Trap: adding dependsOn is unnecessary and can slow deployment.
“Pass an admin password without it appearing in deployment history” → @secure() parameter (securestring in ARM). Trap: a plain string parameter.
“Deploy a Bicep file at subscription scope” → targetScope = 'subscription' and az deployment sub create --location. Trap: az deployment group create needs a resource group.
“Redeploy a vnet template and the subnets vanished” → Define subnets in the vnet subnets property; omitted properties reset to defaults on redeploy.
“User can write VMs but the template deployment is denied” → They also need Microsoft.Resources/deployments/*.
“Required elements of an ARM template” → $schema, contentVersion, resources. Trap: parameters and outputs are optional.
“Deploy a resource only when a bool parameter is true” → Bicep if (param) / ARM condition.
Sources
- Deployment modes
- Bicep file structure and syntax
- ARM template structure and syntax
- Iterative loops in Bicep
- Copy resources (ARM)
- Bicep resource dependencies
- Decompile ARM to Bicep
- Export a template in the portal
- Deploy Bicep with Azure CLI
- What-if
Checked against Microsoft Learn on November 13, 2026.