Use Terraform to provision infrastructure with Azure deployment slots

4/05/2018

5 minutes to read

In this article

You can use Azure deployment slots to swap between different versions of your app. That ability helps you minimize the impact of broken deployments.

This article illustrates an example use of deployment slots by walking you through the deployment of two apps via GitHub and Azure. One app is hosted in a production slot. The second app is hosted in a staging slot. (The names "production" and "staging" are arbitrary and can be anything you want that represents your scenario.) After you configure your deployment slots, you can use Terraform to swap between the two slots as needed.

Prerequisites

Azure subscription: If you don't have an Azure subscription, create a free account before you begin.

GitHub account: You need a GitHub account to fork and use the test GitHub repo.

Deploy from GitHub to your deployment slots

After you fork the test project repo, configure the deployment slots via the following steps:

On the main menu of the Azure portal, select Resource groups.

Select slotDemoResourceGroup.

Select slotAppService.

Select Deployment options.

On the Deployment option tab, select Choose Source, and then select GitHub.

After Azure makes the connection and displays all the options, select Authorization.

On the Authorization tab, select Authorize, and supply the credentials that Azure needs to access your GitHub account.

After Azure validates your GitHub credentials, a message appears and says that the authorization process has finished. Select OK to close the Authorization tab.

Select Choose your organization and select your organization.

Select Choose project.

On the Choose project tab, select the awesome-terraform project.

Select Choose branch.

On the Choose branch tab, select master.

On the Deployment option tab, select OK.

At this point, you have deployed the production slot. To deploy the staging slot, perform all of the previous steps in this section with only the following modifications:

In step 3, select the slotAppServiceSlotOne resource.

In step 13, select the working branch instead of the master branch.

Test the app deployments

In the previous sections, you set up two slots--slotAppService and slotAppServiceSlotOne--to deploy from different branches in GitHub. Let's preview the web apps to validate that they were successfully deployed.

Perform the following steps 2 times. In step 3, you select slotAppService the first time, and then select slotAppServiceSlotOne the second time.

On the main menu of the Azure portal, select Resource groups.

Select slotDemoResourceGroup.

Select either slotAppService or slotAppServiceSlotOne.

On the overview page, select URL.

Note

It can take several minutes for Azure to build and deploy the site from GitHub.

For the slotAppService web app, you see a blue page with a page title of Slot Demo App 1. For the slotAppServiceSlotOne web app, you see a green page with a page title of Slot Demo App 2.

Swap the two deployment slots

To test swapping the two deployment slots, perform the following steps:

Switch to the browser tab that's running slotAppService (the app with the blue page).