1. How to script an Azure Function app creation?


    For creating an Azure Function App, you will primarily need to work with Azure App Service Plan and Function App resources. The App Service Plan represents the resource where the Function App will run and it determines the cost of your function. The Function App resource represents the Azure Function itself.

    This code illustrates how to create an Azure Function app:

    import * as pulumi from "@pulumi/pulumi"; import * as azure from "@pulumi/azure"; // Define the resource group the resources will belong to const resourceGroup = new azure.core.ResourceGroup("MyResourceGroup", { location: "WestUS", }); // Create an Azure Storage Account for the Function App const storageAccount = new azure.storage.Account("mystorage", { resourceGroupName: resourceGroup.name, accountReplicationType: "LRS", accountTier: "Standard", }); // Create an Azure App Service (consumption) Plan const appServicePlan = new azure.appservice.Plan("myconsumptionplan", { resourceGroupName: resourceGroup.name, kind: "FunctionApp", sku: { tier: "Dynamic", size: "Y1", }, }); // Create an Azure Function App within the created App Service Plan const functionApp = new azure.appservice.FunctionApp("myfunctionapp", { resourceGroupName: resourceGroup.name, appServicePlanId: appServicePlan.id, storageConnectionString: storageAccount.primaryConnectionString, });
    1. ResourceGroup: represents the Resource Group in which you will create resources. Location is necessary for creating the Resource Group.
    2. storage.Account: Azure requires an account where it can store files utilized by the function. Here, LRS (Locally redundant storage) and 'Standard' tier are used for the sake of affordability.
    3. appservice.Plan: This represents the plan in which your function app will run. Use "FunctionApp" as the kind. Use tier "Dynamic" and size "Y1" for a consumption plan, which means you only get billed for executions rather than for having your func up.
    4. appservice.FunctionApp: This is your actual function app. You need to supply it with a connection string that it can use to access your storage account.

    The output of the Pulumi up command will include function app's default hostname. Accessing this in a browser will display the default Azure Function App welcome page.