azureblog.co.uk
← AZ-104 study plan
AZ-104 · Deploy and manage Azure compute resources

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. 1

    Interpret an Azure Resource Manager template or a Bicep file

    An ARM template has these main sections: $schema and contentVersion, parameters (values supplied at deployment), variables (values worked out in the template), resources (what to deploy) and outputs (values returned afterwards).

    Bicep has the same ideas with less syntax: param, var, resource and output. Each resource has a symbolic name, a type with an API version such as Microsoft.Storage/storageAccounts@2023-05-01, and its properties.

    Remember: Parameters come in, outputs go out.

  2. 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().location or uniqueString(), and adding resources with dependsOn when 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. 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, @minLength and @secure() add validation.

    Bicep also supports loops with for, conditions with if, and modules to split a deployment into reusable files.

    Remember: Referencing another resource's property creates an implicit dependency.

  4. 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. 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 decompile converts ARM JSON into Bicep. az bicep build compiles 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

  1. WriteA Bicep file or ARM template describes the resources.
  2. ParametersA parameter file supplies values for this environment.
  3. What-ifPreview creates, changes and deletes before anything happens.
  4. DeployAzure Resource Manager validates, then deploys in dependency order.
  5. 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.

  1. Which ARM template section holds values supplied at deployment time?

  2. Which command converts an existing ARM template into Bicep?

  3. What happens to resources not in the template when you deploy in complete mode?

  4. How do you preview what a deployment would change?

  5. Which parameter type stops a password appearing in deployment history?

Sources

Facts in this lesson are from Microsoft Learn. This site isn't affiliated with Microsoft.