Deploy Azure Web App with slots using Azure ARM

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:

ARM Code for creating app service plan
ARM Code for creating app service plan

As it is clear from the above code that we’ll also require to going the two properties named appServiceName and 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:

ARM Code for creating web app / app service
ARM Code for creating web app / app service

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:

ARM Code for Azure Web App Slot
ARM Code for Azure Web App Slot

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s