Table of Contents
If you’ve ever built Azure resources manually in the portal, you know it can be time-consuming and prone to human error. That’s where ARM templates (Azure Resource Manager templates) come in—they allow you to define your infrastructure as code, making deployments consistent, repeatable, and automated.
In this post, we’ll walk through creating an ARM template for an Azure Web App and deploying it using the Azure CLI. By the end, you’ll have a working web app and a solid understanding of how ARM templates streamline cloud automation.
What Exactly Are ARM Templates?
ARM (Azure Resource Manager) templates are JSON-based files that define Azure resources. Instead of manually configuring services in the portal, you describe the desired state once in a template, then deploy it as many times as you want.
Benefits of ARM templates:
- Automation: Deploy with a single command.
- Consistency: Same configuration every time, across dev, test, and production.
- Flexibility: Use parameters for reusability and different environments.
- Tooling Support: Work with them in the portal, PowerShell, Azure CLI, or even CI/CD pipelines.
Why Use ARM Templates?
Beyond just avoiding the manual grind, ARM templates offer several key benefits for automating resource creation:
- Consistency and Repeatability: With a single template, you can deploy identical environments across development, testing, and production. This eliminates configuration drift and reduces human error.
- Version Control: Because templates are code, you can store them in a version control system like Git. This allows you to track changes, collaborate with your team, and easily roll back to previous versions if needed.
- Efficiency and Speed: Deploying complex infrastructure becomes a single command. ARM templates can be integrated into your Continuous Integration/Continuous Deployment (CI/CD) pipelines, allowing for fully automated, end-to-end deployments.
- Modularity: You can break down complex deployments into smaller, reusable components. This allows you to build a library of modular templates that can be linked or nested together to create larger solutions.
Setting Up the Environment
Before writing templates, we’ll set up a few tools:
- Visual Studio Code – A lightweight editor perfect for working with templates.
- Azure Resource Manager Tools extension – Adds schema integration, snippets, and IntelliSense for ARM templates.
- Azure CLI – The command-line tool we’ll use to execute our templates.
To check if you have the Azure CLI installed, run:
az version
If not installed, you can install it with WinGet on Windows:
winget install -e --id Microsoft.AzureCLI
Once installed, restart your terminal and verify the az
command is available.
Creating the ARM Template
Let’s create a file named web-app.json inside VS Code.
Template Structure
An ARM template follows a schema and contains several root properties:
- $schema – URL to the latest ARM schema.
- contentVersion – A version identifier for version control.
- parameters – Input values for flexibility (e.g., app names, regions).
- variables – Calculated values based on parameters.
- resources – The Azure resources we want to create (the heart of the template).
- outputs – Values displayed after deployment (optional).
Step 1: Define the App Service Plan
The App Service Plan is required to host a web app. Using VS Code snippets (arm-plan
), define it as:
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2022-03-01",
"name": "arm-web-app-plan",
"location": "[resourceGroup().location]",
"sku": {
"name": "F1",
"tier": "Free"
},
"properties": {
"name": "arm-web-app-plan"
}
}
💡 Note: The F1 (Free) tier only allows one free plan per region.
Step 2: Define the Web App
Next, add the web app itself using the arm-web-app
snippet:
{
"type": "Microsoft.Web/sites",
"apiVersion": "2022-03-01",
"name": "arm-web-app-demo",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', 'arm-web-app-plan')]"
],
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', 'arm-web-app-plan')]"
}
}
Wrapping Up
ARM templates are more than just JSON files—they’re a way to bring automation, repeatability, and scalability into your Azure projects. Whether you’re setting up a simple storage account or an entire enterprise-grade infrastructure, ARM templates save you time and reduce mistakes.
If you’re just starting out, try creating a small template (like the storage account example above). Once you’re comfortable, you can expand into more complex solutions and even integrate them into your CI/CD pipelines.
Automation is the future, and ARM templates are your ticket to building smarter in Azure.
This tells Azure:
- Create a web app called arm-web-app-demo
- Place it in the same location as the resource group
- Ensure it depends on (and attaches to) the App Service Plan
Deploying the Template with Azure CLI
Now that the template is ready, let’s deploy it.
- Log in to Azure
az login
This opens a browser window for authentication.
Create a Resource Group (if you don’t have one already):
az group create --name myResourceGroup --location eastus
Deploy the Template:
az deployment group create \
--resource-group myResourceGroup \
--template-file web-app.json
If successful, Azure returns a JSON output with details of the deployment.
Verifying the Deployment
Head over to the Azure Portal, open your Resource Group, and hit refresh. You should see:
- An App Service Plan named
arm-web-app-plan
- A Web App named
arm-web-app-demo
Both resources are live, and the web app is ready to be configured or deployed with your code.
What’s Next?
This example shows just the basics of ARM templates. You can take it further by:
- Adding parameters to make the template reusable.
- Defining multiple resources (databases, storage, networking) in one template.
- Using linked templates for modular designs.
- Exploring Bicep, the newer, more developer-friendly language that compiles to ARM templates.
Wrapping Up
By defining infrastructure in an ARM template and deploying it with the Azure CLI, you’ve automated what would otherwise be several manual steps in the portal. This approach ensures consistency, saves time, and sets you on the path toward full Infrastructure as Code (IaC).
In upcoming posts, we’ll explore Bicep—ARM’s modern successor—for an even smoother developer experience.
🚀 Ready to give it a try? Open VS Code, create your first ARM template, and watch your Azure resources spin up automatically!
Click here to add the full JSON of the combined template (App Service Plan + Web App)
- Design