DEV Community

Cover image for Deploying a Web App with ARM Templates and Azure CLI
Chidera Enyelu
Chidera Enyelu

Posted on

Deploying a Web App with ARM Templates and Azure CLI

Azure CLI is a command-line tool for managing Azure resources, allowing you to create, configure, and manage resources across Azure services efficiently using scripts and automation.

Prepare Your ARM Template
First, you need an ARM template that defines your Azure resources. Here’s a basic example to deploy an App Service Plan and a 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": "2021-01-15",
        "name": "[parameters('appServicePlanName')]",
        "location": "[resourceGroup().location]",
        "sku": {
          "name": "F1",
          "tier": "Free",
          "size": "F1",
          "family": "F",
          "capacity": 1
        }
      },
      {
        "type": "Microsoft.Web/sites",
        "apiVersion": "2021-01-15",
        "name": "[parameters('webAppName')]",
        "location": "[resourceGroup().location]",
        "properties": {
          "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
          "siteConfig": {
            "appSettings": [
              {
                "name": "SCM_DO_BUILD_DURING_DEPLOYMENT",
                "value": "true"
              }
            ]
          }
        }
      }
    ],
    "parameters": {
      "appServicePlanName": {
        "type": "string"
      },
      "webAppName": {
        "type": "string"
      }
    }
  }

Enter fullscreen mode Exit fullscreen mode

Prepare Your Parameters.json file:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "appServicePlanName": {
      "value": "myAppServicePlan"
    },
    "webAppName": {
      "value": "myPhpWebApp43564"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Install and Configure Azure CLI
If you haven’t already installed the Azure CLI, download and install it learn microsoft.com for your operating system. After installation, configure it by logging in:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/exdrq5wbesxet0yn3qqs.png)

bash
Copy code
az login
Enter fullscreen mode Exit fullscreen mode

Create Resource Group
If you don’t already have a resource group, create one using Azure CLI:

bash
Copy code
az group create --name myResourceGroup --location eastus
Enter fullscreen mode Exit fullscreen mode

Image description

Replace myResourceGroup and eastus with your desired resource group name and location.

Deploy the ARM Template
Deploy the ARM template to the resource group using the Azure CLI:

bash
Copy code
az deployment group create \
  --resource-group myResourceGroup \
  --template-file azuredeploy.json \
  --parameters @azuredeploy.parameters.json
Enter fullscreen mode Exit fullscreen mode

Image description

Prepare your Git repository

You download the website from Themewagon and on your VSCode, you open the downloaded, extracted file and push to your repository on github using the git/github comprehensive guide in one of my blog(comprehensive guide to git/github).

Image description

Git Deployment:

Configure Git deployment if you prefer deploying via Git. After you Set up a Git repository and push your code, enter the follwing command to deploy your website using github.

bash
Copy code
az webapp deployment source config \
  --name myWebApp \
  --resource-group myResourceGroup \
  --repo-url https://github.com/username/repo \
  --branch main \
  --git-token your-git-token
Enter fullscreen mode Exit fullscreen mode

Image description

Replace the placeholders with your repository details and access token.

Verify Deployment

Check the deployment status and ensure your web app is running correctly:

Azure Portal: Navigate to your web app in the Azure Portal to check the deployment status and view logs.

Image description

Image description
Azure CLI:

bash
Copy code
az webapp show --resource-group myResourceGroup --name myWebApp
Enter fullscreen mode Exit fullscreen mode

This command provides details about your web app, including its status and URL.

Image description

Clean Up Resources (Optional)
If you want to delete the resources after testing or if they are no longer needed, you can delete the resource group, which will remove all resources within it:

bash
Copy code
az group delete --name myResourceGroup --yes --no-wait

Enter fullscreen mode Exit fullscreen mode

By follwoing these steps above, you should be able to succesfully deploy a webapp using Azure CLI.

Top comments (0)