Merge pull request 'feat: support SSH key injection via Gitea secrets for CI pipelines' (#12) from feat/ci-ssh-key-support into dev
All checks were successful
Terraform Deploy / Validate (push) Successful in 7s
Terraform Deploy / Plan (push) Successful in 9s
Terraform Deploy / Apply (push) Has been skipped

Reviewed-on: #12
This commit was merged in pull request #12.
This commit is contained in:
2026-05-03 17:41:11 +00:00
5 changed files with 28 additions and 5 deletions

View File

@@ -14,6 +14,8 @@ env:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_proxmox_url: ${{ secrets.PROXMOX_URL }} TF_VAR_proxmox_url: ${{ secrets.PROXMOX_URL }}
TF_VAR_proxmox_api_token: ${{ secrets.PROXMOX_API_TOKEN }} TF_VAR_proxmox_api_token: ${{ secrets.PROXMOX_API_TOKEN }}
TF_VAR_proxmox_ssh_private_key: ${{ secrets.PROXMOX_SSH_PRIVATE_KEY }}
TF_VAR_admin_ssh_public_key: ${{ secrets.ADMIN_SSH_PUBLIC_KEY }}
TF_VAR_tailscale_auth_key: ${{ secrets.TAILSCALE_AUTH_KEY }} TF_VAR_tailscale_auth_key: ${{ secrets.TAILSCALE_AUTH_KEY }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }} GIT_TOKEN: ${{ secrets.GIT_TOKEN }}

View File

@@ -14,6 +14,8 @@ env:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_proxmox_url: ${{ secrets.PROXMOX_URL }} TF_VAR_proxmox_url: ${{ secrets.PROXMOX_URL }}
TF_VAR_proxmox_api_token: ${{ secrets.PROXMOX_API_TOKEN }} TF_VAR_proxmox_api_token: ${{ secrets.PROXMOX_API_TOKEN }}
TF_VAR_proxmox_ssh_private_key: ${{ secrets.PROXMOX_SSH_PRIVATE_KEY }}
TF_VAR_admin_ssh_public_key: ${{ secrets.ADMIN_SSH_PUBLIC_KEY }}
TF_VAR_tailscale_auth_key: ${{ secrets.TAILSCALE_AUTH_KEY }} TF_VAR_tailscale_auth_key: ${{ secrets.TAILSCALE_AUTH_KEY }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }} GIT_TOKEN: ${{ secrets.GIT_TOKEN }}

View File

@@ -1,5 +1,10 @@
# Fichier: terraform/prod/02-cloud-init.tf # Fichier: terraform/prod/02-cloud-init.tf
locals {
# Utilise le contenu direct si fourni (CI), sinon lit depuis le fichier (local)
ssh_public_key = var.admin_ssh_public_key != "" ? var.admin_ssh_public_key : file(var.admin_ssh_public_key_path)
}
resource "proxmox_virtual_environment_file" "cloud_config" { resource "proxmox_virtual_environment_file" "cloud_config" {
for_each = var.virtual_machines for_each = var.virtual_machines
@@ -11,7 +16,7 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
data = templatefile("${path.module}/../../cloud-init/user-data.yml.tftpl", { data = templatefile("${path.module}/../../cloud-init/user-data.yml.tftpl", {
# Variables pour définir les informations de l'utilisateur # Variables pour définir les informations de l'utilisateur
username = lookup(each.value, "username", var.default_vm_user) username = lookup(each.value, "username", var.default_vm_user)
ssh_key = file(var.admin_ssh_public_key_path) ssh_key = local.ssh_public_key
# Variables pour définir les informations de la VM # Variables pour définir les informations de la VM
hostname = "${each.key}.${var.domain_suffix}" hostname = "${each.key}.${var.domain_suffix}"

View File

@@ -1,10 +1,10 @@
# ===================================================================== # ==========================================================================
# Déclaration des Providers Terraform # Déclaration des Providers Terraform
# #
# Ce fichier indique à Terraform quels "plugins" il doit # Ce fichier indique à Terraform quels "plugins" il doit
# télécharger pour interagir avec les API externes (Proxmox, etc.) # télécharger pour interagir avec les API externes (Proxmox, etc.)
# et comment les configurer. # et comment les configurer.
# ===================================================================== # ==========================================================================
terraform { terraform {
required_version = ">= 1.5.0" required_version = ">= 1.5.0"
@@ -43,7 +43,8 @@ provider "proxmox" {
api_token = var.proxmox_api_token api_token = var.proxmox_api_token
insecure = true insecure = true
ssh { ssh {
agent = true agent = var.proxmox_ssh_private_key == "" ? true : false
username = "root" username = "root"
private_key = var.proxmox_ssh_private_key != "" ? var.proxmox_ssh_private_key : null
} }
} }

View File

@@ -17,12 +17,25 @@ variable "proxmox_api_token" {
sensitive = true sensitive = true
} }
variable "proxmox_ssh_private_key" {
description = "Clé SSH privée pour la connexion Proxmox (utilisée en CI). Si vide, l'agent SSH local est utilisé."
type = string
sensitive = true
default = ""
}
variable "tailscale_auth_key" { variable "tailscale_auth_key" {
description = "Clé d'authentification Tailscale pour enregistrer les noeuds." description = "Clé d'authentification Tailscale pour enregistrer les noeuds."
type = string type = string
sensitive = true sensitive = true
} }
variable "admin_ssh_public_key" {
description = "Contenu de la clé SSH publique à autoriser (utilisé en CI). Prioritaire sur admin_ssh_public_key_path."
type = string
default = ""
}
variable "admin_ssh_public_key_path" { variable "admin_ssh_public_key_path" {
description = "Chemin vers le fichier de la clé SSH publique à autoriser." description = "Chemin vers le fichier de la clé SSH publique à autoriser."
type = string type = string