feat: support SSH key injection via Gitea secrets for CI pipelines #12
@@ -14,6 +14,8 @@ env:
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
TF_VAR_proxmox_url: ${{ secrets.PROXMOX_URL }}
|
||||
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 }}
|
||||
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ env:
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
TF_VAR_proxmox_url: ${{ secrets.PROXMOX_URL }}
|
||||
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 }}
|
||||
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
# 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" {
|
||||
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", {
|
||||
# Variables pour définir les informations de l'utilisateur
|
||||
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
|
||||
hostname = "${each.key}.${var.domain_suffix}"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# =====================================================================
|
||||
# ==========================================================================
|
||||
# Déclaration des Providers Terraform
|
||||
#
|
||||
# Ce fichier indique à Terraform quels "plugins" il doit
|
||||
# télécharger pour interagir avec les API externes (Proxmox, etc.)
|
||||
# et comment les configurer.
|
||||
# =====================================================================
|
||||
# ==========================================================================
|
||||
|
||||
terraform {
|
||||
required_version = ">= 1.5.0"
|
||||
@@ -43,7 +43,8 @@ provider "proxmox" {
|
||||
api_token = var.proxmox_api_token
|
||||
insecure = true
|
||||
ssh {
|
||||
agent = true
|
||||
username = "root"
|
||||
agent = var.proxmox_ssh_private_key == "" ? true : false
|
||||
username = "root"
|
||||
private_key = var.proxmox_ssh_private_key != "" ? var.proxmox_ssh_private_key : null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,25 @@ variable "proxmox_api_token" {
|
||||
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" {
|
||||
description = "Clé d'authentification Tailscale pour enregistrer les noeuds."
|
||||
type = string
|
||||
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" {
|
||||
description = "Chemin vers le fichier de la clé SSH publique à autoriser."
|
||||
type = string
|
||||
|
||||
Reference in New Issue
Block a user