Deploy resources with ARM templates and Bicep
Read, edit and deploy Azure Resource Manager templates and Bicep files, preview changes with what-if, and export or convert templates.
- 20 min
- 5 concepts
- Try it yourself
- 5-question check
Learn
Infrastructure as code means describing resources in files instead of clicking through the portal. ARM templates are JSON files. Bicep is a simpler language that compiles into ARM JSON, so both deploy through Azure Resource Manager in exactly the same way.
Templates are declarative: you describe the end state and Resource Manager works out how to get there. Deploying the same template twice gives the same result, which is what makes them safe to repeat.
- 1
Interpret an Azure Resource Manager template or a Bicep file
An ARM template has these main sections:
$schemaandcontentVersion,parameters(values supplied at deployment),variables(values worked out in the template),resources(what to deploy) andoutputs(values returned afterwards).Bicep has the same ideas with less syntax:
param,var,resourceandoutput. Each resource has a symbolic name, a type with an API version such asMicrosoft.Storage/storageAccounts@2023-05-01, and its properties.Remember: Parameters come in, outputs go out.
- 2
Modify an existing Azure Resource Manager template
Common changes are adding a parameter so a value isn't hard-coded, using functions such as
resourceGroup().locationoruniqueString(), and adding resources withdependsOnwhen one must be created before another.Parameters can have allowed values, defaults and types such as string, int, bool and securestring. Use a parameter file to supply different values for each environment.
Remember: Use securestring for passwords so the value isn't logged in the deployment history.
- 3
Modify an existing Bicep file
Bicep works out most dependencies itself when one resource refers to another's symbolic name, so you rarely need
dependsOn. Decorators such as@allowed,@minLengthand@secure()add validation.Bicep also supports loops with
for, conditions withif, and modules to split a deployment into reusable files.Remember: Referencing another resource's property creates an implicit dependency.
- 4
Deploy resources by using an Azure Resource Manager template or a Bicep file
Deploy with the portal (Deploy a custom template), Azure CLI (
az deployment group create), Azure PowerShell (New-AzResourceGroupDeployment) or a pipeline. Deployments can target a resource group, subscription, management group or tenant.Run a what-if operation first to preview what would be created, changed or deleted. The default incremental mode leaves resources that aren't in the template alone; complete mode deletes them.
Remember: Complete mode deletes resources in the group that aren't in the template. Use it with care.
- 5
Export a deployment as an Azure Resource Manager template or convert an Azure Resource Manager template to a Bicep file
You can export a template from an existing resource group or from a deployment's history in the portal. Exported templates often need tidying, such as turning hard-coded values into parameters.
az bicep decompileconverts ARM JSON into Bicep.az bicep buildcompiles Bicep into ARM JSON. Decompiling is a best-effort conversion that you should review.Remember: decompile: JSON to Bicep. build: Bicep to JSON.
From file to resources
- WriteA Bicep file or ARM template describes the resources.
- ParametersA parameter file supplies values for this environment.
- What-ifPreview creates, changes and deletes before anything happens.
- DeployAzure Resource Manager validates, then deploys in dependency order.
- OutputsValues such as a resource ID are returned for the next step.
Try it
Click each part of this Bicep file to see what it does.
This interactive part needs JavaScript.
In the portal
- Deploy a custom templateAzure portal: Deploy a custom template > Build your own template in the editor
- See deployment historyAzure portal: Resource groups > your group > Settings > Deployments
- Export a templateAzure portal: Resource groups > your group > Automation > Export template
Key terms
Click a card to see the definition.
Check your understanding
5 questions. Score 80% or more and these skills are marked as confident in your AZ-104 study plan.
Which ARM template section holds values supplied at deployment time?
Parameters are inputs. Variables are calculated in the template; outputs are returned afterwards.
Which command converts an existing ARM template into Bicep?
decompile goes from JSON to Bicep.
What happens to resources not in the template when you deploy in complete mode?
Complete mode makes the group match the template exactly. Incremental is the default.
How do you preview what a deployment would change?
What-if shows creates, changes and deletes without applying them.
Which parameter type stops a password appearing in deployment history?
Secure parameters aren't logged or shown in deployment history.
Sources
- Microsoft Learn: What are ARM templates?
- Microsoft Learn: What is Bicep?
- Microsoft Learn: Bicep deployment what-if operation
- Microsoft Learn: Azure Resource Manager deployment modes
- Microsoft Learn: Decompile ARM template JSON to Bicep
Facts in this lesson are from Microsoft Learn. This site isn't affiliated with Microsoft.