-
Notifications
You must be signed in to change notification settings - Fork 879
/
index.ts
69 lines (58 loc) · 2.5 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
import * as pulumi from "@pulumi/pulumi";
import * as resources from "@pulumi/azure-native/resources";
import * as storage from "@pulumi/azure-native/storage";
import * as web from "@pulumi/azure-native/web";
import { getConnectionString, signedBlobReadUrl } from "./helpers";
// Create a separate resource group for this example.
const resourceGroup = new resources.ResourceGroup("functions-rg");
// Storage account is required by Function App.
// Also, we will upload the function code to the same storage account.
const storageAccount = new storage.StorageAccount("sa", {
resourceGroupName: resourceGroup.name,
sku: {
name: storage.SkuName.Standard_LRS,
},
kind: storage.Kind.StorageV2,
});
// Function code archives will be stored in this container.
const codeContainer = new storage.BlobContainer("zips", {
resourceGroupName: resourceGroup.name,
accountName: storageAccount.name,
});
// Upload Azure Function's code as a zip archive to the storage account.
const codeBlob = new storage.Blob("zip", {
resourceGroupName: resourceGroup.name,
accountName: storageAccount.name,
containerName: codeContainer.name,
source: new pulumi.asset.FileArchive("./javascript"),
});
// Define a Consumption Plan for the Function App.
// You can change the SKU to Premium or App Service Plan if needed.
const plan = new web.AppServicePlan("plan", {
resourceGroupName: resourceGroup.name,
sku: {
name: "Y1",
tier: "Dynamic",
},
});
// Build the connection string and zip archive's SAS URL. They will go to Function App's settings.
const storageConnectionString = getConnectionString(resourceGroup.name, storageAccount.name);
const codeBlobUrl = signedBlobReadUrl(codeBlob, codeContainer, storageAccount, resourceGroup);
const app = new web.WebApp("fa", {
resourceGroupName: resourceGroup.name,
serverFarmId: plan.id,
kind: "functionapp",
siteConfig: {
appSettings: [
{ name: "AzureWebJobsStorage", value: storageConnectionString },
{ name: "FUNCTIONS_EXTENSION_VERSION", value: "~3" },
{ name: "FUNCTIONS_WORKER_RUNTIME", value: "node" },
{ name: "WEBSITE_NODE_DEFAULT_VERSION", value: "~14" },
{ name: "WEBSITE_RUN_FROM_PACKAGE", value: codeBlobUrl },
],
http20Enabled: true,
nodeVersion: "~14",
},
});
export const endpoint = pulumi.interpolate`https://${app.defaultHostName}/api/HelloNode?name=Pulumi`;