1. Answers
  2. Share A Code Example For Creating An Azure App Service Virtual Network Swift Connection With Pulumi Using TypeScript.

Share a Code Example for Creating an Azure App Service Virtual Network Swift Connection With Pulumi Using TypeScript.

Introduction

This guide demonstrates how to create an Azure App Service with a Virtual Network Swift Connection using Pulumi and TypeScript. The primary objective is to enable secure communication between your app and Azure resources by leveraging Azure App Service and Azure Virtual Network. By establishing a Swift Connection, the app can securely access resources within the virtual network.

Step-by-Step Explanation

  1. Create a Resource Group: Start by creating a Resource Group, which acts as a container for all related Azure resources. This step is crucial as it organizes resources in a manageable way.

    const resourceGroup = new azure.resources.ResourceGroup("resourceGroup", {
        resourceGroupName: "myResourceGroup",
        location: "WestUS",
    });
    
  2. Create a Virtual Network: Set up a Virtual Network with a subnet to facilitate secure communication between resources within Azure.

    const virtualNetwork = new azure.network.VirtualNetwork("virtualNetwork", {
        resourceGroupName: resourceGroup.name,
        location: resourceGroup.location,
        addressSpace: { addressPrefixes: ["10.0.0.0/16"] },
    });
    
    const subnet = new azure.network.Subnet("subnet", {
        resourceGroupName: resourceGroup.name,
        virtualNetworkName: virtualNetwork.name,
        addressPrefix: "10.0.1.0/24",
    });
    
  3. Create an App Service Plan: Define an App Service Plan, specifying the region and pricing tier, which will host the App Service.

    const appServicePlan = new azure.web.AppServicePlan("appServicePlan", {
        resourceGroupName: resourceGroup.name,
        location: resourceGroup.location,
        sku: {
            name: "B1",
            tier: "Basic",
        },
    });
    
  4. Create an App Service: Deploy an App Service within the specified App Service Plan to host your web application.

    const appService = new azure.web.WebApp("appService", {
        resourceGroupName: resourceGroup.name,
        location: resourceGroup.location,
        serverFarmId: appServicePlan.id,
        siteConfig: {
            appSettings: [{
                name: "WEBSITE_RUN_FROM_PACKAGE",
                value: "1",
            }],
        },
    });
    
  5. Create a Virtual Network Swift Connection: Establish a Swift Connection to link the App Service with the Virtual Network, enabling secure access to network resources.

    const swiftConnection = new azure.web.WebAppSwiftVirtualNetworkConnection("swiftConnection", {
        resourceGroupName: resourceGroup.name,
        name: appService.name,
        subnetResourceId: subnet.id,
    });
    

Key Points

  • Resource Group: Essential for organizing and managing related Azure resources.
  • Virtual Network: Facilitates secure communication between Azure resources.
  • App Service Plan: Determines the hosting environment’s region and pricing tier.
  • App Service: A platform for building, deploying, and scaling web applications.
  • Virtual Network Swift Connection: Enables secure access to resources within the Virtual Network.

Conclusion

By following this guide, you can successfully create an Azure App Service with a Virtual Network Swift Connection using Pulumi and TypeScript. This setup ensures that your App Service can securely access resources within the Virtual Network, enhancing the security and functionality of your Azure applications.

Full Code Example

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: "myResourceGroup",
    location: "WestUS",
});

// Create a Virtual Network
const virtualNetwork = new azure.network.VirtualNetwork("virtualNetwork", {
    resourceGroupName: resourceGroup.name,
    location: resourceGroup.location,
    addressSpace: { addressPrefixes: ["10.0.0.0/16"] },
});

// Create a Subnet
const subnet = new azure.network.Subnet("subnet", {
    resourceGroupName: resourceGroup.name,
    virtualNetworkName: virtualNetwork.name,
    addressPrefix: "10.0.1.0/24",
});

// 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_RUN_FROM_PACKAGE",
            value: "1",
        }],
    },
});

// Create a Virtual Network Swift Connection
const swiftConnection = new azure.web.WebAppSwiftVirtualNetworkConnection("swiftConnection", {
    resourceGroupName: resourceGroup.name,
    name: appService.name,
    subnetResourceId: subnet.id,
});

export const resourceGroupName = resourceGroup.name;
export const virtualNetworkName = virtualNetwork.name;
export const subnetName = subnet.name;
export const appServicePlanName = appServicePlan.name;
export const appServiceName = appService.name;
export const swiftConnectionName = swiftConnection.name;

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