Automating Azure with ARM Templates: Web App + App Service Plan Deployment

8

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

Setting Up the Environment

Before writing templates, we’ll set up a few tools:

  1. Visual Studio Code – A lightweight editor perfect for working with templates.
  2. Azure Resource Manager Tools extension – Adds schema integration, snippets, and IntelliSense for ARM templates.
  3. 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.

{
"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:

{
"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')]"
}
}

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.

  1. Log in to Azure
az login

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.

Full ARM Template Example

Here’s the full ready-to-use ARM template combining both the App Service Plan and the Web App:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"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"
}
},
{
"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')]"
}
}
]
}

Save this JSON as web-app.json, and run the deployment command to spin up your web app. 🚀

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.

In the next section we will add the parameterized version of this template

80%
Awesome
  • Design
Leave A Reply

Your email address will not be published.

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock