1. Answers
  2. Setting Up an Azure App Service Slot

How do I set up an Azure app service slot?

In this guide, we will set up an Azure App Service Slot using Pulumi. An App Service Slot allows you to create deployment slots for your web app, which can be used for staging, testing, and other purposes without affecting your production environment.

Key Points

  • We will create an Azure App Service.
  • We will create an Azure App Service Plan.
  • We will create an Azure App Service Slot within the App Service.

Below is the code to achieve this:

import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure-native";

// Create an Azure Resource Group
const resourceGroup = new azure.resources.ResourceGroup("resourceGroup", {
    resourceGroupName: "exampleResourceGroup",
    location: "WestEurope",
});

// Create an App Service Plan
const appServicePlan = new azure.web.AppServicePlan("appServicePlan", {
    resourceGroupName: resourceGroup.name,
    location: resourceGroup.location,
    sku: {
        name: "B1",
        tier: "Basic",
    },
});

// Create an App Service
const appService = new azure.web.WebApp("appService", {
    resourceGroupName: resourceGroup.name,
    location: resourceGroup.location,
    serverFarmId: appServicePlan.id,
    siteConfig: {
        appSettings: [
            { name: "WEBSITE_NODE_DEFAULT_VERSION", value: "14.16.0" },
        ],
    },
});

// Create an App Service Slot
const appServiceSlot = new azure.web.WebAppSlot("appServiceSlot", {
    resourceGroupName: resourceGroup.name,
    location: resourceGroup.location,
    serverFarmId: appServicePlan.id,
    siteConfig: {
        appSettings: [
            { name: "WEBSITE_NODE_DEFAULT_VERSION", value: "14.16.0" },
        ],
    },
    name: "staging", // Name of the slot
    slot: "staging",
});

Summary

In this guide, we created an Azure Resource Group, an App Service Plan, an App Service, and an App Service Slot using Pulumi. The App Service Slot is named “staging” and can be used for staging deployments without affecting the production environment. This setup allows for smoother transitions and testing of new features before they go live.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up