forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyConfig.cs
68 lines (59 loc) · 1.82 KB
/
MyConfig.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
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using Pulumi;
using Pulumi.Random;
using Pulumi.Tls;
/// <summary>
/// Configures the example. If password and public key for connecting
/// to the cluster are not set with `pulumi config`, we generate a
/// random password and key pair.
/// </summary>
class MyConfig
{
public string K8SVersion { get; set; }
public int NodeCount { get; set; }
public string NodeSize { get; set; }
public PrivateKey GeneratedKeyPair { get; set; }
public string AdminUserName { get; set; }
public Output<string> Password { get; set; }
public Output<string> SshPublicKey { get; set; }
public MyConfig()
{
var cfg = new Config();
this.K8SVersion = cfg.Get("k8sVersion") ?? "1.18.14";
this.NodeCount = cfg.GetInt32("nodeCount") ?? 2;
this.NodeSize = cfg.Get("nodeSize") ?? "Standard_D2_v2";
this.GeneratedKeyPair = new PrivateKey("ssh-key", new PrivateKeyArgs
{
Algorithm = "RSA",
RsaBits = 4096
});
this.AdminUserName = cfg.Get("adminUserName") ?? "testuser";
var pw = cfg.Get("password");
if (pw == null)
{
this.Password = this.GenerateRandomPassword();
}
else
{
this.Password = Output.Create(pw);
}
var sshPubKey = cfg.Get("sshPublicKey");
if (sshPubKey == null)
{
this.SshPublicKey = this.GeneratedKeyPair.PublicKeyOpenssh;
}
else
{
this.SshPublicKey = Output.Create(sshPubKey);
}
}
private Output<string> GenerateRandomPassword()
{
var pw = new RandomPassword("pw", new RandomPasswordArgs
{
Length = 20,
Special = true
});
return pw.Result;
}
}