From c7a9f6fa06c9ac209aed4355f693582cb9b4d441 Mon Sep 17 00:00:00 2001 From: Almeyric Date: Sun, 23 Aug 2026 14:28:44 +0200 Subject: [PATCH] Migration provider bpg, templates cloud-init propres, cluster k3s HA (control-plane) --- terraform/IT-Konoha/.gitignore | Bin 0 -> 82 bytes terraform/IT-Konoha/.terraform.lock.hcl | 24 ++++ terraform/IT-Konoha/k3s-control-plane.tf | 133 ++++++++++++++++++ terraform/IT-Konoha/provider.tf | 25 ++-- terraform/IT-Konoha/variables.tf | 29 ++-- terraform/IT-Konoha/vms-application.tf | 102 ++++++++++++++ .../vms_standalone/srv_docker_530.tf.md | 62 ++++++++ 7 files changed, 349 insertions(+), 26 deletions(-) create mode 100644 terraform/IT-Konoha/.gitignore create mode 100644 terraform/IT-Konoha/.terraform.lock.hcl create mode 100644 terraform/IT-Konoha/k3s-control-plane.tf create mode 100644 terraform/IT-Konoha/vms-application.tf create mode 100644 terraform/IT-Konoha/vms_standalone/srv_docker_530.tf.md diff --git a/terraform/IT-Konoha/.gitignore b/terraform/IT-Konoha/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..75fe2d45a78faf6956b7d9559fcfb857289eee25 GIT binary patch literal 82 zcmezWFPWi;A(bHoi1Qdq7%~|W8FCnk8T5d3DUhEJWR) v.ip } +} + +# ============================================================================= +# NOTE — Storage du template +# ============================================================================= +# Le template 9000 (et 9001 pour Ubuntu) est stocké sur `VMs_NFS`, storage +# partagé (content-type "Disk image" activé, accessible sur tous les nœuds). +# Le clonage cross-node fonctionne donc directement, sans étape manuelle. +# +# Vérifier avant tout `terraform apply` que `each.value.datastore_id` pointe +# bien vers un storage réellement disponible sur le nœud cible (`pvesm status` +# sur chaque nœud) — en particulier pour PVE02, dont le storage local n'a pas +# encore été vérifié à la date de rédaction de ce fichier. +# ============================================================================= diff --git a/terraform/IT-Konoha/provider.tf b/terraform/IT-Konoha/provider.tf index 6a2b630..580f01a 100644 --- a/terraform/IT-Konoha/provider.tf +++ b/terraform/IT-Konoha/provider.tf @@ -1,24 +1,21 @@ terraform { required_providers { proxmox = { - source = "Telmate/proxmox" - version = "3.0.2-rc07" + source = "bpg/proxmox" + version = "0.111.1" } } } provider "proxmox" { - pm_api_url = "https://192.168.76.43:8006/api2/json" - pm_api_token_id = "terraform-prov@pve!mytoken" - pm_api_token_secret = "5af2e198-4a8e-49ef-9a1e-56a6718e3abd" - pm_tls_insecure = true + endpoint = var.proxmox_endpoint + api_token = var.proxmox_api_token # format complet : "user@realm!tokenid=secret-uuid" + insecure = true # certificat auto-signé - # Limiter le parallélisme force le provider à être plus séquentiel sur les droits - pm_parallel = 1 - - # Optionnel : désactive le scan complet du stockage au démarrage - pm_timeout = 600 - # Ajoute ces deux lignes pour stabiliser la session API - pm_log_enable = true - pm_log_file = "terraform-plugin-proxmox.log" + # SSH optionnel, seulement nécessaire pour certaines opérations avancées + # (upload de fichiers/snippets, import de disques bruts, etc.) + # ssh { + # agent = true + # username = "root" + # } } \ No newline at end of file diff --git a/terraform/IT-Konoha/variables.tf b/terraform/IT-Konoha/variables.tf index 110b9aa..82553ee 100644 --- a/terraform/IT-Konoha/variables.tf +++ b/terraform/IT-Konoha/variables.tf @@ -1,19 +1,24 @@ -# Accès SSH -variable "admin_username" { - description = "Nom d'utilisateur pour se connecter à la VM" +# Variables pour le projet IT-Konoha +# Ces variables peuvent être utilisées dans les fichiers .tf pour rendre la configuration plus flexible et réutilisable. + +variable "proxmox_endpoint" { + description = "URL du endpoint Proxmox (ex: https://192.168.76.43:8006/) — SANS /api2/json à la fin" type = string - default = "admin.almeyric" } -/* variable "ssh_public_key" { - description = "Clé publique SSH" +variable "proxmox_api_token" { + description = "Token API complet Proxmox : user@realm!tokenid=secret" type = string sensitive = true -} */ +} -# Tag environnement -variable "environment_tag" { - description = "Indique l'environnement de déploiement (dev, test, prod)" +variable "node_name" { + description = "Nœud Proxmox cible" type = string - default = "test" -} \ No newline at end of file + default = "pve00" +} + +variable "vm_user_sshkey" { + description = "Clé publique SSH injectée via cloud-init" + type = string +} diff --git a/terraform/IT-Konoha/vms-application.tf b/terraform/IT-Konoha/vms-application.tf new file mode 100644 index 0000000..061c698 --- /dev/null +++ b/terraform/IT-Konoha/vms-application.tf @@ -0,0 +1,102 @@ +# ============================================================================= +# VMs applicatives — patron générique (map + for_each) +# ============================================================================= +# Remplace l'ancien srv_docker_530.tf. Même structure que k3s-control-plane.tf : +# une entrée dans `local.nodes` = une VM. Facile à dupliquer pour un futur +# groupe de VMs (copier ce fichier, changer le nom des locals/resource/output). +# +# Actuellement vide de VM "vivante" : .20 (Immich) a été retiré du state +# Terraform (modifiée à la main, cf. historique) et .21 a été détruite lors +# du nettoyage du pool ZFS. Ajouter une entrée dans `local.nodes` pour toute +# nouvelle VM applicative à déployer sur ce modèle. +# ============================================================================= + +variable "nodes_sshkeys_file" { + description = "Fichier de clés SSH autorisées (cluster + poste de travail)" + type = string + default = "./sshkeys.pub" +} + +locals { + # Exemple de structure attendue pour une future VM : + # "srv-jellyfin" = { + # node_name = "pve03" + # vm_id = 533 + # ip = "192.168.30.22" + # gateway = "192.168.30.254" + # vlan_id = 530 + # datastore_id = "local-lvm" + # cores = 2 + # memory = 2048 + # disk_size = 20 + # } + nodes = {} +} + +resource "proxmox_virtual_environment_vm" "nodes" { + for_each = local.nodes + + name = each.key + node_name = each.value.node_name + vm_id = each.value.vm_id + + clone { + vm_id = 9000 # template debian13-cloudinit-template (stockage partagé VMs_NFS) + full = true + } + + agent { + enabled = true + } + + cpu { + cores = each.value.cores + sockets = 1 + type = "x86-64-v2" + } + + memory { + dedicated = each.value.memory + } + + scsi_hardware = "virtio-scsi-single" + + disk { + datastore_id = each.value.datastore_id + interface = "scsi0" + size = each.value.disk_size + iothread = true + } + + network_device { + bridge = "vmbr0" + model = "virtio" + vlan_id = each.value.vlan_id + } + + initialization { + datastore_id = each.value.datastore_id + + ip_config { + ipv4 { + address = "${each.value.ip}/24" + gateway = each.value.gateway + } + } + + user_account { + username = "root" + keys = [for line in split("\n", replace(trimspace(file(var.nodes_sshkeys_file)), "\r", "")) : line if line != ""] + } + } + + operating_system { + type = "l26" + } + + stop_on_destroy = true +} + +output "nodes_ips" { + value = { for k, v in local.nodes : k => v.ip } +} diff --git a/terraform/IT-Konoha/vms_standalone/srv_docker_530.tf.md b/terraform/IT-Konoha/vms_standalone/srv_docker_530.tf.md new file mode 100644 index 0000000..1f807c8 --- /dev/null +++ b/terraform/IT-Konoha/vms_standalone/srv_docker_530.tf.md @@ -0,0 +1,62 @@ +resource "proxmox_virtual_environment_vm" "nodes" { + count = 2 + name = "srv-docker-${count.index + 1}" + node_name = var.node_name + vm_id = 530 + count.index + + clone { + vm_id = 8999 # vmid de ton template debian13-cloudinit + full = true + } + + agent { + enabled = true + } + + cpu { + cores = 2 + sockets = 1 + type = "host" + } + + memory { + dedicated = 4096 + } + + scsi_hardware = "virtio-scsi-single" + + disk { + datastore_id = "VM_POOL_RAID10" + interface = "scsi0" + size = 20 + iothread = true + } + + network_device { + bridge = "vmbr1" + model = "virtio" + vlan_id = 530 + } + + initialization { + datastore_id = "VM_POOL_RAID10" # stockage du disque cloud-init (ide2 par défaut) + + ip_config { + ipv4 { + address = "192.168.30.2${count.index}/24" + gateway = "192.168.30.254" + } + } + + user_account { + username = "root" + keys = [var.vm_user_sshkey] + } + } + + operating_system { + type = "l26" # Linux 2.6+ kernel (Debian, Ubuntu, etc.) + } + + stop_on_destroy = true +} \ No newline at end of file