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>
namespace AzureAks {
class MyConfig {
public string K8SVersion { get; set; }
public int SystemNodeCount { get; set; }
public string SystemNodeSize { get; set; }
public Input<int> CoreNodeCount { get; set; }
public Input<string> CoreNodeSize { get; set; }
public Input<int> GpuNodeCount { get; set; }
public Input<string> GpuNodeSize { 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();
K8SVersion = cfg.Get("k8sVersion") ?? "1.23.3";
SystemNodeCount = cfg.GetInt32("nodeCount") ?? 2;
SystemNodeSize = cfg.Get("nodeSize") ?? "standard_d2ads_v5";
CoreNodeCount = cfg.GetInt32("coreNodeCount") ?? 0;
CoreNodeSize = cfg.Get("coreNodeSize") ?? "standard_b2ms";
GpuNodeCount = cfg.GetInt32("gpuNodeCount") ?? 0;
GpuNodeSize = cfg.Get("gpuNodeSize") ?? "standard_nc4as_t4_v3";
GeneratedKeyPair = new PrivateKey("ssh-key", new PrivateKeyArgs {
Algorithm = "RSA",
RsaBits = 4096
});
AdminUserName = cfg.Get("adminUserName") ?? "testuser";
var pw = cfg.Get("password");
if (pw == null) {
Password = GenerateRandomPassword();
} else {
this.Password = Output.Create(pw);
}
var sshPubKey = cfg.Get("sshPublicKey");
if (sshPubKey == null) {
SshPublicKey = GeneratedKeyPair.PublicKeyOpenssh;
} else {
SshPublicKey = Output.Create(sshPubKey);
}
}
private Output<string> GenerateRandomPassword() {
var pw = new RandomPassword("pw", new RandomPasswordArgs {
Length = 20,
Special = true
});
return pw.Result;
}
}
}