Azure app service provisioning essentials: A guide to scripting your way to efficient azure resource creation using ARM template and CI/CD

Introduction

Sumeet Patil
Villa Plus Engineering
4 min readMar 18, 2024

--

In the fast-paced realm of cloud computing, provisioning an Azure App Service efficiently is vital for seamless application deployment. This blog post delves into the benefits of provisioning, guiding you through the template creation, maintaining a repository, and establishing a release pipeline to automate resource creation.

Let’s first understand the benefits of provisioning!

1. Speed and agility: Provisioning automates the resource creation reducing the efforts and time.

2. Consistency: As your application evolves, you may keep updating the azure resources configurations. In this case the template can be modified accordingly and kept up to date.

3. Disaster recovery: Imagine an app service that has been in production for a while and you need to recover it manually with all its configurations, its relevant resources like application insights, database and many more. If you have provisioned the resources, with few clicks your resources will be ready. It significantly reduces the downtime in case of disaster recovery.

4. Cost-efficiency: The automated resource creation can save a lot of development time over the manual resource creation.

Creating ARM template for Azure App Service

ARM template is basically a textual representation of your azure resource. A basic ARM template for an App service can look like this.

At first glance the template might look complex to read. Once you are used to it, it will be lot easier to understand every part of it. The template essentially requires three sections -

1. Schema — It describes the template version which depends on the scope of deployment and JSON editor.

2. Content version — It defines the version of the template being used.

3. Resources — This contains the resources that are configured or updated.

All 3 of above are required elements in your ARM template. There are few more optional elements which can be used to simplify or better configure the resource.

This ARM template is designed specifically for an application, encompassing the essential and pertinent resources needed. However, it’s important to note that separate templates can be created for any kind of resources like Key Vault, Storage Account, Service Bus etc. There’s no strict requirement to combine all resources into a single template. The principle is to maintain distinct templates for relevant resources, ensuring a modular and organized approach to infrastructure provisioning.

Template JSON file:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"appServicePlanName": {
"type": "string"
},
"webAppName": {
"type": "string",
"defaultValue": "test-mywebapp"
},
"location": {
"type": "string",
"defaultValue": "ukwest"
},
"workspaceName": {
"type": "string"
},
"appInsightsName": {
"type": "string"
},
"slotName": {
"type": "string"
}
// Add other parameters as needed
},
"resources": [
{
// Define App Service Plan properties
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2021-02-01",
"name": "[parameters('appServicePlanName')]"
},
{
// Define web app properties
"type": "Microsoft.Web/sites",
"apiVersion": "2021-02-01",
"name": "[parameters('webAppName')]",
"identity": {
"type": "SystemAssigned"
}
},
{
// Define Application Insights Workspace properties
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2021-12-01-preview",
"name": "[parameters('workspaceName')]",
"location": "[parameters('location')]",
"properties": {
"sku": {
"name": "pergb2018"
}
}
},
{
// Define Application Insights properties
"type": "Microsoft.Insights/components",
"apiVersion": "2020-02-02",
"name": "[parameters('appInsightsName')]",
"dependsOn": [
"[resourceId('Microsoft.OperationalInsights/workspaces', 'workspaceName')]"
]
},
{
// Define deployment slot properties
"type": "Microsoft.Web/sites/slots",
"apiVersion": "2021-02-01",
"name": "[concat(parameters('webAppName'), '/', parameters('slotName'))]",
"identity": {
"type": "SystemAssigned"
}
}
]
}

Parameters JSON file for test environment:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webAppName": {
"value": "test-mywebapp"
},
"location": {
"value": "ukwest"
},
"appInsightsName": {
"value": "test-mywebapp-insights"
},
"slotName": {
"value": "test-mywebapp-staging"
},
"appServicePlanName": {
"value": "test-myappserviceplan"
},
"workspaceName": {
"value": "test-workspace"
}
}
}

To deploy this template across various environments, leverage parameter files to generate environment-specific values. Subsequently, these parameters are substituted within the template. The release pipeline references the parameter file, executing the replacement of variables in the template with their respective parameter values. There should be as many parameter files as the environments.

Creating a CI/CD pipeline for resource deployment

The ARM template is now ready. Next step would be to keep these templates in the repository. There are several ways to deploy the ARM template. We will go with the CI/CD pipeline deployment. The last step is creating the release pipeline to deploy your azure app service with its relevant resources.

Steps on high level to create the release pipeline

1. Create a release pipeline and attach your provisioning repository as an artifact in the Azure DevOps.

2. Add a stage per environment.

3. Create a task of type ARM template deployment.

4. Select the necessary options under the task. (Refer to the image below)

5. Select the template file and environment specific parameters file.

6. Follow above steps from 2 to 5 for another environment specific resource.

Creating a release pipeline in Azure VSTS portal
Release pipeline creation

Once the deployment finishes without any errors, you have successfully created required azure resources for your application. As the application evolves, you will encounter need for the configuration changes. The ARM template can be updated with respective changes. It is ideal to setup provisioning for your application in the initial stage and with enough practice you can follow resource creation through provisioning scripts.

As a final tip, you have the option to export ARM templates directly from the Azure portal for the resources you create. For example, you can manually set up a resource in your dev or test environment, configure it as needed, and then export the template. This allows you to obtain a starting point for your ARM templates and make any necessary modifications to tailor them to your specific requirements.

Conclusion

In essence, the journey of provisioning an Azure App Service through ARM templates is a strategic investment. It enables you to navigate the intricacies of cloud deployment with precision, resilience, and scalability, ensuring your applications thrive in the ever-evolving landscape of cloud computing.

--

--