Créer conteneur lxc dans proxmox


🧱 1. Installer Terraform

Sur ta Surface Pro (Windows probablement) :

👉 Télécharge Terraform depuis le site officiel (zip)

Ensuite :

Puis dans un terminal :

terraform version

👉 Si tu vois une version → OK


🔑 2. Créer un accès API Proxmox

Dans Proxmox :

a. Créer un utilisateur Terraform

Datacenter → Permissions → Users

user : terraform@pve

b. Créer un API Token

Datacenter → Permissions → API Tokens

👉 Note bien :

c. Donner les droits

👉 Important sinon ça ne marchera pas

Permissions → Add


📁 3. Créer ton projet Terraform

mkdir terraform-proxmox cd terraform-proxmox

Crée un fichier :

main.tf

⚙️ 4. Configurer Terraform + Provider

Dans main.tf :

resource "proxmox_virtual_environment_container" "test_lxc" {
  node_name = "pve"

  vm_id = 101
  hostname = "test-lxc"

  initialization {
    hostname = "test-lxc"
  }

  operating_system {
    template_file_id = "local:vztmpl/debian-12-standard_12.0-1_amd64.tar.zst"
  }

  cpu {
    cores = 2
  }

  memory {
    dedicated = 512
  }

  network_interface {
    name = "eth0"
    bridge = "vmbr0"
  }

  rootfs {
    storage = "local-lvm"
    size    = "8G"
  }
}

👉 Remplace :


📦 5. Ajouter un LXC

⚠️ Avant ça :

👉 Tu dois avoir un template LXC déjà téléchargé dans Proxmox (ex: Debian 12)

Ajoute dans main.tf :

resource "proxmox_virtual_environment_container" "test_lxc" { node_name = "pve" vm_id = 101 hostname = "test-lxc" initialization { hostname = "test-lxc" } operating_system { template_file_id = "local:vztmpl/debian-12-standard_12.0-1_amd64.tar.zst" } cpu { cores = 2 } memory { dedicated = 512 } network_interface { name = "eth0" bridge = "vmbr0" } rootfs { storage = "local-lvm" size = "8G" } } 

🚀 6. Lancer Terraform

Dans le dossier :

Initialiser

terraform init

👉 Ça télécharge le provider Proxmox

Voir ce qu’il va faire

terraform plan

👉 Très important : ça te montre le résultat AVANT

Appliquer

terraform apply

👉 Tape yes


🎉 Résultat

👉 Ton LXC est créé automatiquement dans Proxmox

Sans interface web. Juste du code.


🧠 Ce que tu viens d’apprendre


Revision #3
Created 2026-04-24 20:11:11 UTC by Nico là
Updated 2026-04-24 20:22:36 UTC by Nico là