forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path__main__.py
77 lines (68 loc) · 2.09 KB
/
__main__.py
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
from pulumi import asset, export, Output
from pulumi_azure import core, storage, appservice
resource_group = core.ResourceGroup("linuxrg")
http_storage_account = storage.Account(
"http",
account_kind="StorageV2",
account_tier="Standard",
account_replication_type="LRS",
resource_group_name=resource_group.name,
)
http_container=storage.Container(
"http",
storage_account_name=http_storage_account.name,
container_access_type="private"
)
http_zib_blob=storage.Blob(
"http",
storage_account_name=http_storage_account.name,
storage_container_name=http_container.name,
type="Block",
source=asset.AssetArchive({
".": asset.FileArchive("./python")
}))
def get_sas(args):
blob_sas = storage.get_account_blob_container_sas(
connection_string=args[1],
start="2020-01-01",
expiry="2030-01-01",
container_name=args[2],
permissions={
"read": "true",
"write": "false",
"delete": "false",
"list": "false",
"add": "false",
"create": "false"
}
)
return f"https://{args[0]}.blob.core.windows.net/{args[2]}/{args[3]}{blob_sas.sas}"
http_signed_blob_url = Output.all(
http_storage_account.name,
http_storage_account.primary_connection_string,
http_container.name, http_zib_blob.name
).apply(get_sas)
http_plan=appservice.Plan(
"http",
resource_group_name=resource_group.name,
kind="Linux",
sku={
"tier": "Dynamic",
"size": "Y1"
},
reserved="true"
)
http_function_app=appservice.FunctionApp(
"http",
resource_group_name=resource_group.name,
app_service_plan_id=http_plan.id,
storage_account_name=http_storage_account.name,
storage_account_access_key=http_storage_account.primary_access_key,
version="~3",
app_settings={
"FUNCTIONS_WORKER_RUNTIME": "python",
"WEBSITE_RUN_FROM_PACKAGE": http_signed_blob_url,
},
)
export("endpoint", http_function_app.default_hostname.apply(
lambda endpoint: "https://" + endpoint + "/api/HelloPython?name=Pulumi"))