diff --git a/CloudController.cs b/CloudController.cs index 4d116d8..4a3ff0a 100644 --- a/CloudController.cs +++ b/CloudController.cs @@ -2,6 +2,7 @@ using System.Text.Json; using HetznerCloudApi; using HetznerCloudApi.Object.ServerType; +using HetznerCloudApi.Object.SshKey; using HetznerCloudApi.Object.Universal; using Prometheus; using RandomFriendlyNameGenerator; @@ -63,6 +64,10 @@ public async Task CreateNewRunner(string arch, string size, string runne // Grab server type List srvTypes = await _client.ServerType.Get(); long? srvType = srvTypes.FirstOrDefault(x => x.Name == vmSize)?.Id; + + // Grab SSH keys + List sshKeys = await _client.SshKey.Get(); + List srvKeys = sshKeys.Select(x => x.Id).ToList(); // Create new server string runnerVersion = "2.315.0"; @@ -76,7 +81,7 @@ public async Task CreateNewRunner(string arch, string size, string runne .AppendLine($" - [ sh, -xc, 'cd /opt/actions-runner && RUNNER_ALLOW_RUNASROOT=true ./config.sh --url https://github.com/{orgName} --token {runnerToken} --ephemeral --disableupdate --labels {size} && RUNNER_ALLOW_RUNASROOT=true ./run.sh ']") .ToString(); _logger.LogInformation($"Launching VM {name}"); - var newSrv = await _client.Server.Create(eDataCenter.nbg1, imageId.Value, name, srvType.Value, userData: cloudInitcontent); + var newSrv = await _client.Server.Create(eDataCenter.nbg1, imageId.Value, name, srvType.Value, userData: cloudInitcontent, sshKeysIds: srvKeys); _activeRunners.Add(new Machine { Id = newSrv.Id,