Compare commits
4 Commits
b652694b26
...
43ba14df60
| Author | SHA1 | Date | |
|---|---|---|---|
| 43ba14df60 | |||
|
|
a9fdb3ac45 | ||
|
|
a66142632c | ||
|
|
f3f84168c3 |
52
cloud-init/user-data-alpine.yml.tftpl
Normal file
52
cloud-init/user-data-alpine.yml.tftpl
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#cloud-config
|
||||||
|
|
||||||
|
# 1. Hostname configuration
|
||||||
|
hostname: ${hostname}
|
||||||
|
fqdn: ${hostname}
|
||||||
|
preserve_hostname: false
|
||||||
|
|
||||||
|
# 2. User creation
|
||||||
|
# On Alpine, the privilege escalation group is "wheel" (not "sudo").
|
||||||
|
# Keep the default shell (ash/busybox) to stay lightweight.
|
||||||
|
users:
|
||||||
|
- name: ${username}
|
||||||
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
|
groups: wheel
|
||||||
|
ssh_authorized_keys:
|
||||||
|
- ${ssh_key}
|
||||||
|
|
||||||
|
# 3. apk repositories configuration
|
||||||
|
# Pin the two repositories used on this homelab: edge/main + edge/community.
|
||||||
|
# Written BEFORE package_update/package_upgrade so apk uses this config immediately.
|
||||||
|
write_files:
|
||||||
|
- path: /etc/apk/repositories
|
||||||
|
owner: root:root
|
||||||
|
permissions: '0644'
|
||||||
|
content: |
|
||||||
|
http://dl-cdn.alpinelinux.org/alpine/edge/main
|
||||||
|
http://dl-cdn.alpinelinux.org/alpine/edge/community
|
||||||
|
|
||||||
|
# 4. System update (apk)
|
||||||
|
package_update: true
|
||||||
|
package_upgrade: true
|
||||||
|
|
||||||
|
# 5. Package installation
|
||||||
|
# - qemu-guest-agent: main repo (required so Proxmox/Terraform can read the VM IP)
|
||||||
|
# - tailscale: community repo
|
||||||
|
packages:
|
||||||
|
- qemu-guest-agent
|
||||||
|
- curl
|
||||||
|
- sudo
|
||||||
|
- tailscale
|
||||||
|
|
||||||
|
# 6. Services & configuration (OpenRC, not systemd)
|
||||||
|
# Intentional order: qemu-guest-agent first to unblock Terraform as soon as possible.
|
||||||
|
runcmd:
|
||||||
|
# Enable and start qemu-guest-agent via OpenRC
|
||||||
|
- [ rc-update, add, qemu-guest-agent, default ]
|
||||||
|
- [ rc-service, qemu-guest-agent, start ]
|
||||||
|
# Enable and start Tailscale via OpenRC
|
||||||
|
- [ rc-update, add, tailscale, default ]
|
||||||
|
- [ rc-service, tailscale, start ]
|
||||||
|
# Register the node with the tailnet
|
||||||
|
- [ tailscale, up, --authkey=${tailscale_auth_key}, --hostname=${vm_name} ]
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
#cloud-config
|
#cloud-config
|
||||||
|
|
||||||
# 1. Configuration du nom d'hôte de la machine
|
# 1. Hostname configuration
|
||||||
hostname: ${hostname}
|
hostname: ${hostname}
|
||||||
fqdn: ${hostname}
|
fqdn: ${hostname}
|
||||||
preserve_hostname: false
|
preserve_hostname: false
|
||||||
|
|
||||||
# 2. Création de l'utilisateur
|
# 2. User creation
|
||||||
users:
|
users:
|
||||||
- name: ${username}
|
- name: ${username}
|
||||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
@@ -14,16 +14,16 @@ users:
|
|||||||
ssh_authorized_keys:
|
ssh_authorized_keys:
|
||||||
- ${ssh_key}
|
- ${ssh_key}
|
||||||
|
|
||||||
# 3. Mise à jour du système
|
# 3. System update
|
||||||
package_update: true
|
package_update: true
|
||||||
package_upgrade: true
|
package_upgrade: true
|
||||||
|
|
||||||
# 4. Installation des paquets
|
# 4. Package installation
|
||||||
packages:
|
packages:
|
||||||
- qemu-guest-agent
|
- qemu-guest-agent
|
||||||
- curl
|
- curl
|
||||||
|
|
||||||
# 5. Installation et configuration de Tailscale
|
# 5. Tailscale installation and configuration
|
||||||
runcmd:
|
runcmd:
|
||||||
# Enable and start qemu-guest-agent (systemd)
|
# Enable and start qemu-guest-agent (systemd)
|
||||||
- [ systemctl, enable, qemu-guest-agent, --now ]
|
- [ systemctl, enable, qemu-guest-agent, --now ]
|
||||||
@@ -78,6 +78,11 @@ resource "proxmox_virtual_environment_vm" "vms" {
|
|||||||
|
|
||||||
# On utilise le bloc 'initialization' pour configurer Cloud-Init
|
# On utilise le bloc 'initialization' pour configurer Cloud-Init
|
||||||
initialization {
|
initialization {
|
||||||
|
# Configuration DNS (nécessaire au bootstrap : apt, curl, install Tailscale...)
|
||||||
|
dns {
|
||||||
|
servers = var.dns_servers
|
||||||
|
}
|
||||||
|
|
||||||
# Configuration IP
|
# Configuration IP
|
||||||
ip_config {
|
ip_config {
|
||||||
ipv4 {
|
ipv4 {
|
||||||
|
|||||||
@@ -1,8 +1,18 @@
|
|||||||
# Fichier: terraform/prod/02-cloud-init.tf
|
# File: terraform/prod/02-cloud-init.tf
|
||||||
|
|
||||||
locals {
|
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)
|
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" {
|
resource "proxmox_virtual_environment_file" "cloud_config" {
|
||||||
@@ -13,18 +23,21 @@ resource "proxmox_virtual_environment_file" "cloud_config" {
|
|||||||
content_type = "snippets"
|
content_type = "snippets"
|
||||||
|
|
||||||
source_raw {
|
source_raw {
|
||||||
data = templatefile("${path.module}/../../cloud-init/user-data.yml.tftpl", {
|
data = templatefile(
|
||||||
# Variables pour définir les informations de l'utilisateur
|
"${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)
|
username = lookup(each.value, "username", var.default_vm_user)
|
||||||
ssh_key = local.ssh_public_key
|
ssh_key = local.ssh_public_key
|
||||||
|
|
||||||
# Variables pour définir les informations de la VM
|
# VM information
|
||||||
hostname = "${each.key}.${var.domain_suffix}"
|
hostname = "${each.key}.${var.domain_suffix}"
|
||||||
|
|
||||||
# Nouvelles variables pour Tailscale
|
# Tailscale variables
|
||||||
vm_name = each.key # Le nom de la VM (ex: "web-01")
|
vm_name = each.key
|
||||||
tailscale_auth_key = var.tailscale_auth_key
|
tailscale_auth_key = var.tailscale_auth_key
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
file_name = "${each.key}-cloud-init.yml"
|
file_name = "${each.key}-cloud-init.yml"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ variable "default_vm_user" {
|
|||||||
default = "root"
|
default = "root"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "dns_servers" {
|
||||||
|
description = "Liste des serveurs DNS pour les VMs (utilisés au bootstrap, avant la prise en charge éventuelle par Tailscale ou un autre service)."
|
||||||
|
type = list(string)
|
||||||
|
default = ["192.168.1.254"]
|
||||||
|
}
|
||||||
|
|
||||||
variable "virtual_machines" {
|
variable "virtual_machines" {
|
||||||
description = "Configuration des machines virtuelles à déployer"
|
description = "Configuration des machines virtuelles à déployer"
|
||||||
type = map(object({
|
type = map(object({
|
||||||
|
|||||||
Reference in New Issue
Block a user