Remove legacy cloud-init template

The user-data.yml.tftpl file was replaced with OS-specific templates to
support
different init systems. The new templates are
user-data-systemd.yml.tftpl and
user-data-alpine.yml.tftpl, selected based on the VM's OS type.
This commit is contained in:
Damien
2026-06-10 08:09:36 +02:00
parent b652694b26
commit f3f84168c3
2 changed files with 25 additions and 44 deletions

View File

@@ -1,32 +0,0 @@
#cloud-config
# 1. Configuration du nom d'hôte de la machine
hostname: ${hostname}
fqdn: ${hostname}
preserve_hostname: false
# 2. Création de l'utilisateur
users:
- name: ${username}
sudo: ALL=(ALL) NOPASSWD:ALL
groups: sudo, admin
shell: /bin/bash
ssh_authorized_keys:
- ${ssh_key}
# 3. Mise à jour du système
package_update: true
package_upgrade: true
# 4. Installation des paquets
packages:
- qemu-guest-agent
- curl
# 5. Installation et configuration de Tailscale
runcmd:
# Enable and start qemu-guest-agent (systemd)
- [ systemctl, enable, qemu-guest-agent, --now ]
# Install and configure Tailscale
- [ sh, -c, "curl -fsSL https://tailscale.com/install.sh | sh" ]
- [ tailscale, up, --authkey=${tailscale_auth_key}, --hostname=${vm_name} ]

View File

@@ -1,8 +1,18 @@
# Fichier: terraform/prod/02-cloud-init.tf
# File: terraform/prod/02-cloud-init.tf
locals {
# Utilise le contenu direct si fourni (CI), sinon lit depuis le fichier (local)
# Use direct content if provided (CI), otherwise read from file (local).
ssh_public_key = var.admin_ssh_public_key != "" ? var.admin_ssh_public_key : file(var.admin_ssh_public_key_path)
# OS -> cloud-init template family mapping.
# Selects the correct user-data based on init system / package manager.
os_template_family = {
ubuntu = "systemd"
debian = "systemd"
rocky = "systemd"
ipfabric = "systemd"
alpine = "alpine"
}
}
resource "proxmox_virtual_environment_file" "cloud_config" {
@@ -13,18 +23,21 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
content_type = "snippets"
source_raw {
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 = local.ssh_public_key
data = templatefile(
"${path.module}/../../cloud-init/user-data-${local.os_template_family[each.value.os]}.yml.tftpl",
{
# User information
username = lookup(each.value, "username", var.default_vm_user)
ssh_key = local.ssh_public_key
# Variables pour définir les informations de la VM
hostname = "${each.key}.${var.domain_suffix}"
# VM information
hostname = "${each.key}.${var.domain_suffix}"
# Nouvelles variables pour Tailscale
vm_name = each.key # Le nom de la VM (ex: "web-01")
tailscale_auth_key = var.tailscale_auth_key
})
# Tailscale variables
vm_name = each.key
tailscale_auth_key = var.tailscale_auth_key
}
)
file_name = "${each.key}-cloud-init.yml"
}