forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
89 lines (78 loc) · 2.78 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
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
import * as docker from "@pulumi/docker";
import * as pulumi from "@pulumi/pulumi";
import * as app from "@pulumi/azure-native/app";
import * as containerregistry from "@pulumi/azure-native/containerregistry";
import * as operationalinsights from "@pulumi/azure-native/operationalinsights";
import * as resources from "@pulumi/azure-native/resources";
const resourceGroup = new resources.ResourceGroup("rg");
const workspace = new operationalinsights.Workspace("loganalytics", {
resourceGroupName: resourceGroup.name,
sku: {
name: "PerGB2018",
},
retentionInDays: 30,
});
const workspaceSharedKeys = operationalinsights.getSharedKeysOutput({
resourceGroupName: resourceGroup.name,
workspaceName: workspace.name,
});
const managedEnv = new app.ManagedEnvironment("env", {
resourceGroupName: resourceGroup.name,
appLogsConfiguration: {
destination: "log-analytics",
logAnalyticsConfiguration: {
customerId: workspace.customerId,
sharedKey: workspaceSharedKeys.apply((r: operationalinsights.GetSharedKeysResult) => r.primarySharedKey!),
},
},
});
const registry = new containerregistry.Registry("registry", {
resourceGroupName: resourceGroup.name,
sku: {
name: "Basic",
},
adminUserEnabled: true,
});
const credentials = containerregistry.listRegistryCredentialsOutput({
resourceGroupName: resourceGroup.name,
registryName: registry.name,
});
const adminUsername = credentials.apply((c: containerregistry.ListRegistryCredentialsResult) => c.username!);
const adminPassword = credentials.apply((c: containerregistry.ListRegistryCredentialsResult) => c.passwords![0].value!);
const customImage = "node-app";
const myImage = new docker.Image(customImage, {
imageName: pulumi.interpolate`${registry.loginServer}/${customImage}:v1.0.0`,
build: { context: `./${customImage}` },
registry: {
server: registry.loginServer,
username: adminUsername,
password: adminPassword,
},
});
const containerApp = new app.ContainerApp("app", {
resourceGroupName: resourceGroup.name,
managedEnvironmentId: managedEnv.id,
configuration: {
ingress: {
external: true,
targetPort: 80,
},
registries: [{
server: registry.loginServer,
username: adminUsername,
passwordSecretRef: "pwd",
}],
secrets: [{
name: "pwd",
value: adminPassword,
}],
},
template: {
containers: [{
name: "myapp",
image: myImage.imageName,
}],
},
});
export const url = pulumi.interpolate`https://${containerApp.configuration.apply((c: any) => c?.ingress?.fqdn)}`;