In this article, you’re going to learn how to create a simple Azure ARM template and deploy it into Azure using the Azure CLI.
If you’re still manually building resources in the Azure Portal, there’s a much better way - Azure Resource Manager (ARM) templates. Azure ARM templates allow you to define one, ten, or 100 different components in Azure to create them all at once. They are also idempotent, meaning repeated deployments will only update what’s changed.
ARM templates are JSON files that can be created with any text editor. Each Azure ARM template defines each resource to create (or update) along with various attributes and configuration settings.
When you finish creating an ARM template, what is next? Deployment. Using a few different methods, you can deploy Azure resources via a single ARM template via PowerShell, Azure CLI, among others.
ARM templates are like snowflakes - no template is alike. Every ARM template is going to look a little different depending on the resource to provision, and it’s attributes. But, the following JSON snippet does represent a common schema each template must follow.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "",
"parameters": { },
"variables": { },
"functions": [ ],
"resources": [ ],
"outputs": { }
}
Building an Azure ARM template can be a daunting task. ARM templates can grow into the thousands of lines! If you’re just getting started, it’s best to use an example. Rather than creating your own, download the *Very simple deployment of a Windows VM* ARM template found on GitHub.
For hundreds of examples of how to build ARM templates, be sure to check out all of the Azure Quickstart Templates on GitHub.
Ensure you download both the azuredeploy.json and azuredeploy.parameters.json files.
We don’t have near enough time in this tutorial to explain the ARM template in depth. I encourage you to review the template and parameters ahead of time. Also, be sure to check out the handy ARM visualization link to see what resources the deployment creates once the deployment runs.
When you have the ARM template and optional parameters file, you can now initiate the deployment to create the resources.
Assuming you’ve downloaded the Azure CLI and have authenticated, let’s now create a resource group to deploy to. Most ARM templates will deploy to resource groups. Templates also support deployment to subscriptions too.
This tutorial will be using a resource group called ARMTemplateTutorial located in the East US Azure region. You’ll see how to create this resource group in the following snippet.
az group create --name *ARMTemplateTutorial* --location "East US"
When the above command is complete, you will see a JSON output like the following screenshot.
Once you have a resource group created, you can then deploy all resources in the ARM template using the az group deployment create command.
In the following snippet, the Azure CLI is:
Run the deployment and notice what happens. You will receive a deployment error. When the deployment runs, the template is validated for any kind of syntax or schema errors. If it finds any, it notices you, as shown in the screenshot below.
Fix the error by providing a valid domain name label. This domain name label is passed as a parameter value in the dnsLabelPrefix parameter.
The dnsLabelPrefix parameter should look like the following:
"dnsLabelPrefix": {
"value": "genunique"
}
Try to rerun the deployment. This time, it should start running. But the joy only lasts for so long. The deployment will return another error indicating the adminPassword parameter doesn’t match the required syntax.
This time, however, you will see that the deployment has already provisioned some infrastructure. In the following screenshot, you can see the resources created in the tutorial’s environment.
Update the adminPassword parameter to P@$$w0rd12 to match the security requirements and try the deployment again. Notice that even though the deployment creates some resources already, a second deployment is not affected. It is smart enough to know to skip them.
This time the deployment will successfully run. Now recheck the Azure portal. You should see the deployment creates all of the resources defined in the ARM template.
In this tutorial, you learned the basics of how an Azure ARM template is built and how to deploy resources within to Azure. You also learned how to perform basic troubleshooting when template deployment fails validation.
Use the skills learned in this tutorial to guide you on creating and deploying all of your ARM template in your environment!
Adam Bertram is a 25+ year IT veteran and an experienced online business professional. He’s a successful blogger, consultant, 6x Microsoft MVP, trainer, published author and freelance writer for dozens of publications. For how-to tech tutorials, catch up with Adam at adamtheautomator.com, connect on LinkedIn or follow him on X at @adbertram.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites