Deploy an ARM template and export one
In this task you'll deploy an ARM template from the portal.
Infrastructure as code means describing your resources in a file and letting Azure build them from it, instead of clicking. The same file gives the same result every time, and it can be reviewed and kept in version control like any other code.
Azure's own format is the ARM template: a JSON file listing resources and their settings. The portal's Deploy a custom template page runs one, and Export template shows the template for resources you've already made.
Example. Larkfield Group keeps one template for every new project: a network, a network security group and standard tags. Each new team deploys it in two minutes, and every project starts out the same.
Before you start
You need: Contributor on the resource group. Time: 15 minutes.
Where to look
- Home
- Deploy a custom template
- Build your own template in the editor
Steps
- Search Deploy a custom template and select Build your own template in the editor.
- Select Add resource and choose Availability set from the short list of common resources. Type avset-from-template in Name and select OK. Read the JSON: it now has a parameter for the set's name and the set itself in its
resourcessection.An availability set on its own is free, so it's a safe resource to practise with. - Select Save. On the Basics page choose rg-portal-practice and your region, and type avset-practice in the name box. Select Review + create, read the summary and its terms, then Create.
- Open rg-portal-practice and select Deployments under Settings. Open your deployment and look at its Inputs, Outputs and Template.Every create in the portal is a deployment, so this list also shows the resources you made by clicking.
- Open avset-practice and select Export template under Automation. It has ARM template, Bicep and Terraform tabs: the same resource in three languages.Exported templates are a good starting point, but tidy them before reusing: they include every setting, even defaults.
- Deploy the same template again with the same name. It succeeds without making a second set: templates describe the end state.
Commands
# Deploy an ARM template file to a resource group
az deployment group create --resource-group rg-portal-practice --template-file template.json
# Export a resource group's resources as a template
az group export --name rg-portal-practice > exported.json
# List past deployments
az deployment group list --resource-group rg-portal-practice --output table
Watch out for
- Cost
- Deploying is free; you pay for what the template creates. Read a template before deploying it, and check the summary page for anything paid.
- Security
- Never put passwords in a template or its parameters file. Use secure parameters and Key Vault references. Only deploy templates you trust, because they can create anything your account can.
- Common mistakes
- Changing a resource by hand after deploying it, so the template no longer matches. Using Complete mode by accident, which deletes resources in the group that aren't in the template.
Clean up
- rg-portal-practice
- avset-practice
- Delete
Delete avset-practice, or delete the resource group at the end of this section. The deployment history is removed with the group.
Words to know
- ARM template
- A JSON file that describes Azure resources for Azure Resource Manager to create.
- Parameter
- A value you fill in when you deploy, such as a name or a region.
- Deployment
- One run of a template. Each resource group keeps a history of them.
- Idempotent
- Running it again gives the same result: nothing is created twice.
Tick off each step and track your progress in the guide.
Open this task in Azure Portal, Hands On