-
Notifications
You must be signed in to change notification settings - Fork 880
/
MyStack.cs
125 lines (114 loc) · 4.29 KB
/
MyStack.cs
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
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using Pulumi;
using Pulumi.AzureNative.ContainerRegistry;
using Pulumi.AzureNative.ContainerRegistry.Inputs;
using Pulumi.AzureNative.OperationalInsights;
using Pulumi.AzureNative.OperationalInsights.Inputs;
using Pulumi.AzureNative.Resources;
using Pulumi.AzureNative.App;
using Pulumi.AzureNative.App.Inputs;
using Pulumi.Docker;
using ContainerArgs = Pulumi.AzureNative.App.Inputs.ContainerArgs;
using SecretArgs = Pulumi.AzureNative.App.Inputs.SecretArgs;
class MyStack : Stack
{
public MyStack()
{
var resourceGroup = new ResourceGroup("rg");
var workspace = new Workspace("loganalytics", new WorkspaceArgs
{
ResourceGroupName = resourceGroup.Name,
Sku = new WorkspaceSkuArgs { Name = "PerGB2018" },
RetentionInDays = 30,
});
var workspaceSharedKeys = Output.Tuple(resourceGroup.Name, workspace.Name).Apply(items =>
GetSharedKeys.InvokeAsync(new GetSharedKeysArgs
{
ResourceGroupName = items.Item1,
WorkspaceName = items.Item2,
}));
var managedEnv = new ManagedEnvironment("env", new ManagedEnvironmentArgs
{
ResourceGroupName = resourceGroup.Name,
AppLogsConfiguration = new AppLogsConfigurationArgs
{
Destination = "log-analytics",
LogAnalyticsConfiguration = new LogAnalyticsConfigurationArgs
{
CustomerId = workspace.CustomerId,
SharedKey = workspaceSharedKeys.Apply(r => r.PrimarySharedKey)
}
}
});
var registry = new Registry("registry", new RegistryArgs
{
ResourceGroupName = resourceGroup.Name,
Sku = new SkuArgs { Name = "Basic" },
AdminUserEnabled = true
});
var credentials = Output.Tuple(resourceGroup.Name, registry.Name).Apply(items =>
ListRegistryCredentials.InvokeAsync(new ListRegistryCredentialsArgs
{
ResourceGroupName = items.Item1,
RegistryName = items.Item2
}));
var adminUsername = credentials.Apply(credentials => credentials.Username);
var adminPassword = credentials.Apply(credentials => credentials.Passwords[0].Value);
var customImage = "node-app";
var myImage = new Image(customImage, new ImageArgs
{
ImageName = Output.Format($"{registry.LoginServer}/{customImage}:v1.0.0"),
Build = new DockerBuild { Context = $"./{customImage}" },
Registry = new ImageRegistry
{
Server = registry.LoginServer,
Username = adminUsername,
Password = adminPassword
}
});
var containerApp = new ContainerApp("app", new ContainerAppArgs
{
ResourceGroupName = resourceGroup.Name,
ManagedEnvironmentId = managedEnv.Id,
Configuration = new ConfigurationArgs
{
Ingress = new IngressArgs
{
External = true,
TargetPort = 80
},
Registries =
{
new RegistryCredentialsArgs
{
Server = registry.LoginServer,
Username = adminUsername,
PasswordSecretRef = "pwd",
}
},
Secrets =
{
new SecretArgs
{
Name = "pwd",
Value = adminPassword
}
},
},
Template = new TemplateArgs
{
Containers =
{
new ContainerArgs
{
Name = "myapp",
Image = myImage.ImageName,
}
}
}
});
this.Url = Output.Format($"https://{containerApp.Configuration.Apply(c => c.Ingress).Apply(i => i.Fqdn)}");
}
[Output("url")]
public Output<string> Url { get; set; }
}