How do I host multiple web apps within a single App Service Plan?
To host multiple web apps within a single App Service Plan on Azure using Pulumi, we will follow these steps:
- Create an Azure Resource Group: Resource groups in Azure are logical containers into which Azure resources like web apps, databases, and storage accounts are deployed and managed.
- Create an App Service Plan: An App Service Plan defines the region, instance size, and scaling options for web apps.
- Create Multiple Web Apps: Each web app will be hosted within the single App Service Plan we created.
We’ll use the azure-native
package, which provides native support for Azure resources. Below is a detailed explanation followed by the Pulumi program written in TypeScript.
Detailed Explanation
- Resource Group: This is a container that holds related resources for an Azure solution. It includes those resources that you want to manage as a group.
- App Service Plan: This provides the underlying compute resources for your web apps. It defines the region, instance size, and scaling options.
- Web Apps: These are the actual applications that you want to deploy. They will share the compute resources defined in the App Service Plan.
Pulumi Program
import * as pulumi from "@pulumi/pulumi";
import * as azureNative from "@pulumi/azure-native";
// Create an Azure Resource Group
const resourceGroup = new azureNative.resources.ResourceGroup("resourceGroup", {
resourceGroupName: "myResourceGroup",
location: "WestEurope",
});
// Create an App Service Plan
const appServicePlan = new azureNative.web.AppServicePlan("appServicePlan", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
sku: {
name: "B1",
tier: "Basic",
capacity: 1,
},
});
// Create the first Web App
const webApp1 = new azureNative.web.WebApp("webApp1", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
serverFarmId: appServicePlan.id,
siteConfig: {
appSettings: [
{
name: "WEBSITE_RUN_FROM_PACKAGE",
value: "1",
},
],
},
});
// Create the second Web App
const webApp2 = new azureNative.web.WebApp("webApp2", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
serverFarmId: appServicePlan.id,
siteConfig: {
appSettings: [
{
name: "WEBSITE_RUN_FROM_PACKAGE",
value: "1",
},
],
},
});
// Export the URLs of the web apps
export const webApp1Url = webApp1.defaultHostName.apply(hostName => `https://${hostName}`);
export const webApp2Url = webApp2.defaultHostName.apply(hostName => `https://${hostName}`);
Explanation of the Code
- Resource Group: We create a resource group named
myResourceGroup
in theWestEurope
region. - App Service Plan: We create an App Service Plan named
appServicePlan
in the same resource group and region. The plan uses theBasic
pricing tier with one instance. - Web Apps: We create two web apps (
webApp1
andwebApp2
) within the same App Service Plan. Each web app is configured to run from a package. - Export URLs: We export the URLs of the two web apps so you can easily access them after deployment.
This Pulumi program sets up an environment where two web apps share the same compute resources defined by a single App Service Plan, making it cost-effective and easy to manage.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.