forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
224 lines (195 loc) · 8.16 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
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 * as pulumi from "@pulumi/pulumi";
// Create a resource group for Windows App Service Plan
const resourceGroup = new resources.ResourceGroup("windowsrg");
const storageAccount = new storage.StorageAccount("functionsa", {
resourceGroupName: resourceGroup.name,
kind: storage.Kind.StorageV2,
sku: {
name: storage.SkuName.Standard_LRS,
},
});
const plan = new web.AppServicePlan("windows-plan", {
resourceGroupName: resourceGroup.name,
sku: {
name: "Y1",
tier: "Dynamic",
},
});
const container = new storage.BlobContainer("container", {
accountName: storageAccount.name,
resourceGroupName: resourceGroup.name,
publicAccess: storage.PublicAccess.None,
});
const dotnetBlob = new storage.Blob("dotnetBlob", {
resourceGroupName: resourceGroup.name,
accountName: storageAccount.name,
containerName: container.name,
source: new pulumi.asset.FileArchive("./dotnet/bin/Debug/netcoreapp3.1/publish"),
});
const dotnetBlobSignedURL = signedBlobReadUrl(dotnetBlob, container, storageAccount, resourceGroup);
const dotnetApp = new web.WebApp("httpdotnet", {
resourceGroupName: resourceGroup.name,
serverFarmId: plan.id,
kind: "FunctionApp",
siteConfig: {
appSettings: [
{ name: "runtime", value: "dotnet" },
{ name: "FUNCTIONS_WORKER_RUNTIME", value: "dotnet" },
{ name: "WEBSITE_RUN_FROM_PACKAGE", value: dotnetBlobSignedURL },
{ name: "FUNCTIONS_EXTENSION_VERSION", value: "~3" },
],
},
});
const nodeBlob = new storage.Blob("nodeBlob", {
resourceGroupName: resourceGroup.name,
accountName: storageAccount.name,
containerName: container.name,
source: new pulumi.asset.FileArchive("./javascript"),
});
const nodeBlobSignedURL = signedBlobReadUrl(nodeBlob, container, storageAccount, resourceGroup);
const nodeApp = new web.WebApp("httpnode", {
resourceGroupName: resourceGroup.name,
serverFarmId: plan.id,
kind: "FunctionApp",
siteConfig: {
appSettings: [
{ name: "runtime", value: "node" },
{ name: "FUNCTIONS_WORKER_RUNTIME", value: "node" },
{ name: "WEBSITE_RUN_FROM_PACKAGE", value: nodeBlobSignedURL },
{ name: "WEBSITE_NODE_DEFAULT_VERSION", value: "~12" },
{ name: "FUNCTIONS_EXTENSION_VERSION", value: "~3" },
],
},
});
const powershellBlob = new storage.Blob("powershellBlob", {
resourceGroupName: resourceGroup.name,
accountName: storageAccount.name,
containerName: container.name,
source: new pulumi.asset.FileArchive("./powershell"),
});
const powershellBlobSignedURL = signedBlobReadUrl(powershellBlob, container, storageAccount, resourceGroup);
const powershellApp = new web.WebApp("httppowershell", {
resourceGroupName: resourceGroup.name,
serverFarmId: plan.id,
kind: "FunctionApp",
siteConfig: {
appSettings: [
{ name: "runtime", value: "powershell" },
{ name: "FUNCTIONS_WORKER_RUNTIME", value: "powershell" },
{ name: "WEBSITE_RUN_FROM_PACKAGE", value: powershellBlobSignedURL },
{ name: "FUNCTIONS_EXTENSION_VERSION", value: "~3" },
],
},
});
const javaBlob = new storage.Blob("javaBlob", {
resourceGroupName: resourceGroup.name,
accountName: storageAccount.name,
containerName: container.name,
source: new pulumi.asset.FileArchive("./java/target/azure-functions/fabrikam-functions"),
});
const javaBlobSignedURL = signedBlobReadUrl(javaBlob, container, storageAccount, resourceGroup);
const javaApp = new web.WebApp("httpjava", {
resourceGroupName: resourceGroup.name,
serverFarmId: plan.id,
kind: "FunctionApp",
siteConfig: {
appSettings: [
{ name: "runtime", value: "java" },
{ name: "FUNCTIONS_WORKER_RUNTIME", value: "java" },
{ name: "WEBSITE_RUN_FROM_PACKAGE", value: javaBlobSignedURL },
{ name: "FUNCTIONS_EXTENSION_VERSION", value: "~3" },
],
},
});
// Create a dedicated resource group for Linux App Service Plan - require for Python
const linuxResourceGroup = new resources.ResourceGroup("linuxrg");
// Python Function App won't run on Windows Consumption Plan, so we create a Linux Consumption Plan instead
const linuxPlan = new web.AppServicePlan("linux-asp", {
resourceGroupName: linuxResourceGroup.name,
kind: "Linux",
sku: {
name: "Y1",
tier: "Dynamic",
},
reserved: true,
});
const pythonBlob = new storage.Blob("pythonBlob", {
resourceGroupName: resourceGroup.name,
accountName: storageAccount.name,
containerName: container.name,
source: new pulumi.asset.FileArchive("./python"),
});
const pythonBlobSignedURL = signedBlobReadUrl(pythonBlob, container, storageAccount, resourceGroup);
const pythonApp = new web.WebApp("httppython", {
resourceGroupName: resourceGroup.name,
serverFarmId: linuxPlan.id,
kind: "FunctionApp",
siteConfig: {
appSettings: [
{ name: "runtime", value: "python" },
{ name: "FUNCTIONS_WORKER_RUNTIME", value: "python" },
{ name: "WEBSITE_RUN_FROM_PACKAGE", value: pythonBlobSignedURL },
{ name: "FUNCTIONS_EXTENSION_VERSION", value: "~3" },
],
},
});
// Azure Functions on Premium Plan
const premiumPlan = new web.AppServicePlan("premiumasp", {
resourceGroupName: resourceGroup.name,
kind: "elastic",
sku: {
tier: "ElasticPremium",
name: "EP1",
},
maximumElasticWorkerCount: 20,
});
const premiumBlob = new storage.Blob("premiumBlob", {
resourceGroupName: resourceGroup.name,
accountName: storageAccount.name,
containerName: container.name,
source: new pulumi.asset.FileArchive("./dotnet/bin/Debug/netcoreapp3.1/publish"),
});
const premiumBlobSignedURL = signedBlobReadUrl(premiumBlob, container, storageAccount, resourceGroup);
const premiumApp = new web.WebApp("httppremium", {
resourceGroupName: resourceGroup.name,
serverFarmId: premiumPlan.id,
kind: "FunctionApp",
siteConfig: {
appSettings: [
{ name: "runtime", value: "dotnet" },
{ name: "WEBSITE_RUN_FROM_PACKAGE", value: premiumBlobSignedURL },
{ name: "FUNCTIONS_EXTENSION_VERSION", value: "~3" },
],
},
});
function signedBlobReadUrl(blob: storage.Blob,
container: storage.BlobContainer,
account: storage.StorageAccount,
resourceGroup: resources.ResourceGroup): pulumi.Output<string> {
const blobSAS = storage.listStorageAccountServiceSASOutput({
accountName: account.name,
protocols: storage.HttpProtocol.Https,
sharedAccessExpiryTime: "2030-01-01",
sharedAccessStartTime: "2021-01-01",
resourceGroupName: resourceGroup.name,
resource: storage.SignedResource.C,
permissions: storage.Permissions.R,
canonicalizedResource: pulumi.interpolate`/blob/${account.name}/${container.name}`,
contentType: "application/json",
cacheControl: "max-age=5",
contentDisposition: "inline",
contentEncoding: "deflate",
});
const token = blobSAS.serviceSasToken;
return pulumi.interpolate`https://${account.name}.blob.core.windows.net/${container.name}/${blob.name}?${token}`;
}
export const dotnetEndpoint = dotnetApp.defaultHostName.apply(ep => `https://${ep}/api/HelloDotnet?name=Pulumi`);
export const nodeEndpoint = nodeApp.defaultHostName.apply(ep => `https://${ep}/api/HelloNode?name=Pulumi`);
export const powershellEndpoint = powershellApp.defaultHostName.apply(ep => `https://${ep}/api/HelloPS?name=Pulumi`);
export const javaEndpoint = javaApp.defaultHostName.apply(ep => `https://${ep}/api/HelloJava?name=Pulumi`);
export const pythonEndpoint = pythonApp.defaultHostName.apply(ep => `https://${ep}/api/HelloPython?name=Pulumi`);
export const premiumEndpoint = premiumApp.defaultHostName.apply(ep => `https://${ep}/api/HelloDotnet?name=PulumiOnPremium`);