Guide for deploying and exporting ARM templates with Azure CLI, and deploying a web app using those templates
NB you are requested to have a prior knowledge of CLI & ARM for you to go along with this lab.
1. Deploy ARM Templates with Azure CLI
Step 1.1: Understand ARM Templates
ARM templates are JSON files that define Azure resources and their configurations. For this guide:
template.json
: Defines the resources.parameters.json
: Supplies values for parameters defined in the template.
Step 1.2: Prepare the ARM Template and deploy a keyvault
Here’s a simple example to deploy an Azure Storage account:
template.json:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vaultName": {
"type": "string",
"metadata": {
"description": "The name of the key vault to be created."
}
},
"keyName": {
"type": "string",
"metadata": {
"description": "The name of the key to be created."
}
},
Step 1.3: Deploy the ARM Template
Run the following Azure CLI command:
az group create \
--resource-group <ResourceGroupName> \
--template-file template.json \
Replace
<ResourceGroupName>
with your actual resource group name.Ensure the template and parameter files are in the same directory.
you should get something like this if you followed the instruction
The outcome on azure portal
2. Export ARM Templates with Azure CLI
Step 2.1: Export from a Resource Group
To export an ARM template from an existing resource group:
az group export \
--name <ResourceGroupName> \
--output json > exported-template.json
This command saves the ARM template to a JSON file named exported-template.json
.
once done you can go check the azure portal for confirmation
3. Deploy a Web App with ARM Templates and Azure CLI
Before proceeding, create a folder with the name Webapp on you directory because that is where you will be working on.
Step 3.1: Create the Template
For a web app, your template.json
could look like this:
Step 3.1: Create the Template
For a web app, your template.json
could look like this:
{
"$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"
}
}
}
parameters.json:
jsonCopy code{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webAppName": {
"value": "myUniqueWebAppName"
},
"appServicePlanName": {
"value": "myAppServicePlan"
}
}
}
But before we commence, we have to be sure we are on the right directory, doing that you type in cd (name of the directory) eg. cd web-app enter.
create a resource group
az group create \
--resource-group <ResourceGroupName> \
Run the following: to deploy the parameters.json & template.json
az deployment group create \
--resource-group <ResourceGroupName> \
--template-file template.json \
--parameters parameters.json
next is to deploy the website, i believe by now you should have gotten a website to use if not use this Fork Github Repo - LINK
It tells you it works, and it has been deployed, you go to your portal copy the default domain paste it into the browser of your choice