Azure ARM uses simple JSON files for deploying infrastructure in Azure. While creating an azure web app or app service is not that tricky, usually you would require additional settings like deployment slots, application settings, connection strings, custom time zone etc. as well. It would be certainly nice if we can incorporate some of that as part of ARM templates itself so that we need not worry about it later. Since this topic is going to be lengthy, we’ll break into 3-4 smaller posts and also learn few azure resource manager tricks as well along the way. In this blog post, we’ll see how to create an Azure Web app and a slot associated with it using Azure ARM template.
Create an App Service Plan
To deploy a web app, first we need to create an app service plan. We can use below code to create an app service plan. It looks like below code:
As it is clear from the above code that we’ll also require to going the two properties named
appServiceSkuName. So we need to define those two also in our ARM template.
Create an Azure Web App
We can create the web app using below code snippet:
Here, our web app name is defined inside a property named
webAppName. There are two important properties to be noted about above code:
1. We are defining that app service plan is created first and then web app. This is done by mentioning app service plan as part of
dependsOn in web app code.
2. We are associating the app service plan with web app using the
properties section of above code.
Create an deployment slot
Deployment slots are in fact resources of the App Service itself and can be deployed as such. This means you can specify them within the resources array of your web application / App Service. ARM code for deployment slot looks like below:
Here, slot name is defined inside a property named
stagingSlotName. Again, we have made sure that web service exists first before the slot is created by using the
dependsOn in the above code. Since it is defined within the resources array of the web app itself, there is no need to link the two.
Here’s a full copy of the ARM template:
We’ll see in upcoming posts how we can deploy additional settings as part of the template and also improve on above template created.