feat: support SSH key injection via Gitea secrets for CI pipelines #12

Merged
Damien merged 5 commits from feat/ci-ssh-key-support into dev 2026-05-03 17:41:11 +00:00
Owner

Problème

Le provider Proxmox (bpg/proxmox) nécessite une connexion SSH pour uploader les fichiers cloud-init sur le noeud Proxmox. En local, cela fonctionne via l'agent SSH (agent = true), mais en CI (Gitea Actions), l'agent SSH n'est pas disponible et la clé privée n'est pas accessible.

De même, le cloud-init utilise file(var.admin_ssh_public_key_path) pour lire la clé publique depuis le disque, ce qui échoue en CI.

Solution

Fichiers modifiés

  • terraform/prod/variables.tf — Ajout de deux nouvelles variables :

    • proxmox_ssh_private_key : contenu de la clé SSH privée (pour le provider)
    • admin_ssh_public_key : contenu de la clé SSH publique (pour cloud-init)
    • Les deux ont un default vide pour rester rétrocompatibles en local
  • terraform/prod/providers.tf — Le bloc SSH du provider est maintenant conditionnel :

    • Si proxmox_ssh_private_key est fourni → utilise private_key directement
    • Sinon → utilise agent = true (comportement local inchangé)
  • terraform/prod/02-cloud-init.tf — Ajout d'un locals pour résoudre la clé publique :

    • Si admin_ssh_public_key est fourni → utilise le contenu directement
    • Sinon → lit depuis admin_ssh_public_key_path (comportement local inchangé)
  • .gitea/workflows/terraform-deploy.yml et terraform-pr.yml — Ajout des variables d'environnement :

    • TF_VAR_proxmox_ssh_private_key: ${{ secrets.PROXMOX_SSH_PRIVATE_KEY }}
    • TF_VAR_admin_ssh_public_key: ${{ secrets.ADMIN_SSH_PUBLIC_KEY }}

Secrets Gitea à configurer

Ajouter dans Settings > Actions > Secrets du repo iac-homelab :

Secret Valeur
PROXMOX_SSH_PRIVATE_KEY Contenu complet de la clé privée SSH (y compris les lignes -----BEGIN/END-----)
ADMIN_SSH_PUBLIC_KEY Contenu de la clé publique SSH (ex: ssh-rsa AAAA... user@host)

Rétrocompatibilité

En local, aucun changement nécessaire : les variables ont des valeurs par défaut vides, donc le comportement existant (agent SSH + lecture fichier) est préservé.

## Problème Le provider Proxmox (`bpg/proxmox`) nécessite une connexion SSH pour uploader les fichiers cloud-init sur le noeud Proxmox. En local, cela fonctionne via l'agent SSH (`agent = true`), mais en CI (Gitea Actions), l'agent SSH n'est pas disponible et la clé privée n'est pas accessible. De même, le cloud-init utilise `file(var.admin_ssh_public_key_path)` pour lire la clé publique depuis le disque, ce qui échoue en CI. ## Solution ### Fichiers modifiés - **`terraform/prod/variables.tf`** — Ajout de deux nouvelles variables : - `proxmox_ssh_private_key` : contenu de la clé SSH privée (pour le provider) - `admin_ssh_public_key` : contenu de la clé SSH publique (pour cloud-init) - Les deux ont un default vide pour rester rétrocompatibles en local - **`terraform/prod/providers.tf`** — Le bloc SSH du provider est maintenant conditionnel : - Si `proxmox_ssh_private_key` est fourni → utilise `private_key` directement - Sinon → utilise `agent = true` (comportement local inchangé) - **`terraform/prod/02-cloud-init.tf`** — Ajout d'un `locals` pour résoudre la clé publique : - Si `admin_ssh_public_key` est fourni → utilise le contenu directement - Sinon → lit depuis `admin_ssh_public_key_path` (comportement local inchangé) - **`.gitea/workflows/terraform-deploy.yml`** et **`terraform-pr.yml`** — Ajout des variables d'environnement : - `TF_VAR_proxmox_ssh_private_key: ${{ secrets.PROXMOX_SSH_PRIVATE_KEY }}` - `TF_VAR_admin_ssh_public_key: ${{ secrets.ADMIN_SSH_PUBLIC_KEY }}` ## Secrets Gitea à configurer Ajouter dans **Settings > Actions > Secrets** du repo `iac-homelab` : | Secret | Valeur | |--------|--------| | `PROXMOX_SSH_PRIVATE_KEY` | Contenu complet de la clé privée SSH (y compris les lignes `-----BEGIN/END-----`) | | `ADMIN_SSH_PUBLIC_KEY` | Contenu de la clé publique SSH (ex: `ssh-rsa AAAA... user@host`) | ## Rétrocompatibilité En local, aucun changement nécessaire : les variables ont des valeurs par défaut vides, donc le comportement existant (agent SSH + lecture fichier) est préservé.
Damien added 5 commits 2026-05-03 17:05:09 +00:00
Add proxmox_ssh_private_key for provider SSH in CI pipelines.
Add admin_ssh_public_key as content-based alternative to file path.
Both default to empty string for backward compatibility with local usage.
Use proxmox_ssh_private_key variable when available, otherwise
fall back to SSH agent for local development.
Use admin_ssh_public_key content when provided, otherwise
fall back to reading from admin_ssh_public_key_path file.
Inject PROXMOX_SSH_PRIVATE_KEY and ADMIN_SSH_PUBLIC_KEY
secrets as TF_VAR_ environment variables for CI.
feat: add SSH key env vars to PR workflow
All checks were successful
Terraform PR / Validate (pull_request) Successful in 6s
Terraform PR / Plan (pull_request) Successful in 10s
f57f68b6f3
Inject PROXMOX_SSH_PRIVATE_KEY and ADMIN_SSH_PUBLIC_KEY
secrets as TF_VAR_ environment variables for CI.
Author
Owner

🔍 Terraform Plan

Exit code: 0

  • 0 = No changes
  • 2 = Changes detected
Click to expand plan output
data.proxmox_virtual_environment_vms.templates: Reading...

Planning failed. Terraform encountered an error while generating this plan.


Error: error retrieving VMs: received an HTTP 401 response - Reason: Authentication failed!

  with data.proxmox_virtual_environment_vms.templates,
  on 01-virtual-machines.tf line 5, in data "proxmox_virtual_environment_vms" "templates":
   5: data "proxmox_virtual_environment_vms" "templates" {


Error: Invalid function argument

  on 02-cloud-init.tf line 5, in locals:
   5:   ssh_public_key = var.admin_ssh_public_key != "" ? var.admin_ssh_public_key : file(var.admin_ssh_public_key_path)
    ├────────────────
     while calling file(path)
     var.admin_ssh_public_key_path is "~/.ssh/keys/id_rsa.pub"

Invalid value for "path" parameter: no file exists at
"~/.ssh/keys/id_rsa.pub"; this function works only with files that are
distributed as part of the configuration source code, so if this file will be
created by a resource in this configuration you must instead obtain this
result from an attribute of that resource.
## 🔍 Terraform Plan **Exit code:** `0` - `0` = No changes - `2` = Changes detected <details> <summary>Click to expand plan output</summary> ```hcl data.proxmox_virtual_environment_vms.templates: Reading... Planning failed. Terraform encountered an error while generating this plan. Error: error retrieving VMs: received an HTTP 401 response - Reason: Authentication failed! with data.proxmox_virtual_environment_vms.templates, on 01-virtual-machines.tf line 5, in data "proxmox_virtual_environment_vms" "templates": 5: data "proxmox_virtual_environment_vms" "templates" { Error: Invalid function argument on 02-cloud-init.tf line 5, in locals: 5: ssh_public_key = var.admin_ssh_public_key != "" ? var.admin_ssh_public_key : file(var.admin_ssh_public_key_path) ├──────────────── │ while calling file(path) │ var.admin_ssh_public_key_path is "~/.ssh/keys/id_rsa.pub" Invalid value for "path" parameter: no file exists at "~/.ssh/keys/id_rsa.pub"; this function works only with files that are distributed as part of the configuration source code, so if this file will be created by a resource in this configuration you must instead obtain this result from an attribute of that resource. ``` </details>
Damien merged commit 12e413f2a7 into dev 2026-05-03 17:41:11 +00:00
Damien deleted branch feat/ci-ssh-key-support 2026-05-03 17:41:12 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Damien/iac-homelab#12