From ece3a51097904815a6033525562cc3f2ea42970a Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Sat, 2 Aug 2025 20:41:36 +0200 Subject: [PATCH] fix: Add user for GitHub Actions --- terraform/main.tf | 1 + terraform/modules/docker-network/swarm-node.tf | 1 + .../docker-network/templates/cloud-init-docker.yaml.tftpl | 4 ++++ terraform/modules/docker-network/variables.tf | 5 +++++ terraform/variables.tf | 5 +++++ 5 files changed, 16 insertions(+) diff --git a/terraform/main.tf b/terraform/main.tf index 6b4a22d..4c277dc 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -135,6 +135,7 @@ module "test_swarm_cluster" { admin_user = "2martensAdmin" terraform_public_ssh_key = var.terraform_public_ssh_key terraform_private_ssh_key = var.terraform_private_ssh_key + github_public_ssh_key = var.github_public_ssh_key basic_firewall_id = hcloud_firewall.basic-firewall.id domain = local.domain locations = [ diff --git a/terraform/modules/docker-network/swarm-node.tf b/terraform/modules/docker-network/swarm-node.tf index 060a293..c73c303 100644 --- a/terraform/modules/docker-network/swarm-node.tf +++ b/terraform/modules/docker-network/swarm-node.tf @@ -74,6 +74,7 @@ resource "hcloud_server" "node" { admin_public_ssh_key : format("%s %s", var.admin_ssh_key.public_key, var.admin_ssh_key.name) admin_user : var.admin_user terraform_public_ssh_key : var.terraform_public_ssh_key + github_public_ssh_key : var.github_public_ssh_key main_node : count.index == 0 packages_setup : base64encode(file("${path.module}/templates/scripts/install-packages.sh")) firewall_setup : base64encode(templatefile("${path.module}/templates/scripts/firewall-setup.sh.tftpl", { diff --git a/terraform/modules/docker-network/templates/cloud-init-docker.yaml.tftpl b/terraform/modules/docker-network/templates/cloud-init-docker.yaml.tftpl index 1f34353..c2b3261 100644 --- a/terraform/modules/docker-network/templates/cloud-init-docker.yaml.tftpl +++ b/terraform/modules/docker-network/templates/cloud-init-docker.yaml.tftpl @@ -11,6 +11,10 @@ users: sudo: ALL=(ALL) NOPASSWD:ALL ssh_authorized_keys: - ${terraform_public_ssh_key} + - name: github + groups: users, docker + ssh_authorized_keys: + - ${github_public_ssh_key} package_update: true package_upgrade: true package_reboot_if_required: true diff --git a/terraform/modules/docker-network/variables.tf b/terraform/modules/docker-network/variables.tf index 02f24d7..c6b6fc5 100644 --- a/terraform/modules/docker-network/variables.tf +++ b/terraform/modules/docker-network/variables.tf @@ -23,6 +23,11 @@ variable "terraform_public_ssh_key" { type = string } +variable "github_public_ssh_key" { + description = "Public SSH key for the private key used by GitHub Actions to connect with remote machines" + type = string +} + variable "locations" { description = "Locations in which the resources should be created. Singular resources will always be created in the first. Must be all in the same network zone." type = list(object({ diff --git a/terraform/variables.tf b/terraform/variables.tf index 3954d3b..6ca2dc9 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -49,6 +49,11 @@ variable "terraform_public_ssh_key" { type = string } +variable "github_public_ssh_key" { + description = "Public SSH key for the private key used by GitHub Actions to connect with remote machines" + type = string +} + variable "vault_client_id" { description = "Client ID of the service principal used to access Hashicorp Cloud" type = string