Tutorial: Create and deploy your start ARM template

This tutorial introduces yous to Azure Resources Manager templates (ARM templates). Information technology shows you lot how to create a starter template and deploy it to Azure. You'll larn well-nigh the construction of the template and the tools yous'll need for working with templates. It takes most 12 minutes to complete this tutorial, but the actual fourth dimension will vary based on how many tools you lot need to install.

This tutorial is the first of a series. Every bit you progress through the series, yous modify the starting template step by pace until you've explored all of the cadre parts of an ARM template. These elements are the building blocks for much more than complex templates. We hope by the end of the series you're confident creating your own templates and ready to automate your deployments with templates.

If you want to learn about the benefits of using templates and why you should automate deployment with templates, see ARM template overview. To learn virtually ARM templates through a guided set of modules on Microsoft Learn, meet Deploy and manage resources in Azure by using ARM templates.

If you don't have an Azure subscription, create a free account earlier you begin.

Tip

If you're new to ARM templates, y'all might consider learning Bicep instead. Bicep is a new language that offers the same capabilities every bit ARM templates but with a syntax that's easier to use. To starting time learning Bicep, encounter Quickstart: Create Bicep files with Visual Studio Code.

Let'due south starting time by making sure you take the tools y'all need to create and deploy templates. Install these tools on your local machine.

Editor

Templates are JSON files. To create templates, yous demand a good JSON editor. We recommend Visual Studio Code with the Resource Manager Tools extension. If you lot need to install these tools, see Quickstart: Create ARM templates with Visual Studio Code.

Command-line deployment

You also need either Azure PowerShell or Azure CLI to deploy the template. If you lot apply Azure CLI, you must have the latest version. For the installation instructions, see:

  • Install Azure PowerShell
  • Install Azure CLI on Windows
  • Install Azure CLI on Linux
  • Install Azure CLI on macOS

Subsequently installing either Azure PowerShell or Azure CLI, make sure y'all sign in for the first time. For aid, run into Sign in - PowerShell or Sign in - Azure CLI.

Important

If y'all're using Azure CLI, brand certain you have version 2.6 or later. The commands shown in this tutorial will non piece of work if you're using earlier versions. To check your installed version, employ: az --version.

Okay, you're set to commencement learning about templates.

Create your first template

  1. Open up Visual Studio Code with the Resource Manager Tools extension installed.

  2. From the File menu, select New File to create a new file.

  3. From the File menu, select Salve equally.

  4. Proper noun the file azuredeploy and select the json file extension. The complete proper noun of the file is azuredeploy.json.

  5. Save the file to your workstation. Select a path that is easy to retrieve because you lot'll provide that path later when deploying the template.

  6. Copy and paste the following JSON into the file:

                      {   "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",   "contentVersion": "ane.0.0.0",   "resources": [] }                                  

    Here's what your Visual Studio Lawmaking environs looks like:

    ARM template Visual Studio Code first template

    This template doesn't deploy any resource. Nosotros're starting with a blank template so you tin can get familiar with the steps to deploy a template while minimizing the chance of something going wrong.

    The JSON file has these elements:

    • $schema: Specifies the location of the JSON schema file. The schema file describes the properties that are available within a template. For example, the schema defines resources as i of the valid properties for a template. Don't worry that the date for the schema is 2019-04-01. This schema version is up to engagement and includes all of the latest features. The schema date hasn't been changed because there take been no breaking changes since its introduction.
    • contentVersion: Specifies the version of the template (such as 1.0.0.0). You can provide whatever value for this chemical element. Utilise this value to document significant changes in your template. When deploying resources using the template, this value can be used to make sure that the right template is being used.
    • resources: Contains the resource you want to deploy or update. Currently, it's empty, only y'all'll add resources later on.
  7. Salvage the file.

Congratulations, you've created your kickoff template.

Sign in to Azure

To outset working with Azure PowerShell/Azure CLI, sign in with your Azure credentials.

Select the tabs in the following lawmaking sections to cull between Azure PowerShell and Azure CLI. The CLI examples in this commodity are written for the Bash beat.

  • PowerShell
  • Azure CLI
                  Connect-AzAccount                                  

If you accept multiple Azure subscriptions, select the subscription you lot want to utilise. Supervene upon SubscriptionName with your subscription proper noun. Yous can also use the subscription ID instead of the subscription proper noun.

  • PowerShell
  • Azure CLI
                  Set-AzContext SubscriptionName                                  

Create resource group

When you deploy a template, yous specify a resource group that volition contain the resource. Before running the deployment command, create the resource group with either Azure CLI or Azure PowerShell.

  • PowerShell
  • Azure CLI
                  New-AzResourceGroup `   -Name myResourceGroup `   -Location "Central The states"                                  

Deploy template

To deploy the template, use either Azure CLI or Azure PowerShell. Use the resource group you created. Give a proper noun to the deployment so you lot can easily identify it in the deployment history. For convenience, also create a variable that stores the path to the template file. This variable makes it easier for you to run the deployment commands because you lot don't have to retype the path every time you deploy. Replace {provide-the-path-to-the-template-file} and the curly braces {} with the path to your template file.

  • PowerShell
  • Azure CLI
                  $templateFile = "{provide-the-path-to-the-template-file}" New-AzResourceGroupDeployment `   -Proper name blanktemplate `   -ResourceGroupName myResourceGroup `   -TemplateFile $templateFile                                  

The deployment command returns results. Look for ProvisioningState to run into whether the deployment succeeded.

  • PowerShell
  • Azure CLI

PowerShell deployment provisioning state

Note

If the deployment failed, use the verbose switch to get information about the resources being created. Use the debug switch to get more data for debugging.

Verify deployment

Yous tin verify the deployment by exploring the resource group from the Azure portal.

  1. Sign in to the Azure portal.

  2. From the left card, select Resource groups.

  3. Select the resources group deploy in the last procedure. The default name is myResourceGroup. Yous shall encounter no resource deployed within the resources group.

  4. Find in the upper right of the overview, the status of the deployment is displayed. Select 1 Succeeded.

    View deployment status

  5. You see a history of deployment for the resource grouping. Select blanktemplate.

    Select deployment

  6. You run into a summary of the deployment. In this case, there'southward not a lot to see because no resources were deployed. Afterwards in this series yous might notice it helpful to review the summary in the deployment history. Notice on the left yous can view inputs, outputs, and the template used during deployment.

    View deployment summary

Clean up resource

If yous're moving on to the next tutorial, you don't need to delete the resources group.

If yous're stopping at present, you might want to delete the resource group.

  1. From the Azure portal, select Resource group from the left bill of fare.
  2. Enter the resource group proper noun in the Filter by name field.
  3. Select the resource grouping name.
  4. Select Delete resource group from the top menu.

Next steps

You created a unproblematic template to deploy to Azure. In the side by side tutorial, you'll add together a storage account to the template and deploy it to your resource group.