This commit is contained in:
2026-04-05 20:50:04 +02:00
commit e2dc9305ee
19 changed files with 1124 additions and 0 deletions

24
terraform/.terraform.lock.hcl generated Normal file
View File

@@ -0,0 +1,24 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/telmate/proxmox" {
version = "2.9.14"
constraints = ">= 2.9.14"
hashes = [
"h1:H/f+LbVyPOLslHLAYnGuMMRqWFZ65K6E3V+MCYgfAyk=",
"zh:0d049d33f705e5b814d30028770c084151218439424e99684ce31d7e26a720b5",
"zh:20b1c64ed56d81de95f3f37b82b45b4654c0de26670c0e87a474c5cce13cd015",
"zh:2946058abd1d8e50e475b9ec39781eb02576b40dbd80f4653fade4493a4514c6",
"zh:29e50a25c456f040ce072f23ac57b5b82ebd3b916ca5ae6688332b5ec62adc4a",
"zh:3612932306ce5f08db94868f526cbb8c56d0d3c6ebe1c11a83f92bbf94354296",
"zh:42d1699b0abebaac82ea5a19f4393541d8bb2741bde204a8ac1028cdc29d1b14",
"zh:5ffd5dc567262eb8aafdf2f6eac63f7f21361da9c5d75a3c36b479638a0001b0",
"zh:6692ef323e3b89de99934ad731f6a1850525bf8142916ae28ea4e4048d73a787",
"zh:a5afc98e9a4038516bb58e788cb77dea67a60dce780dfcd206d7373c5a56b776",
"zh:bf902cded709d84fa27fbf91b589c241f2238a6c4924e4e479eebd74320b93a5",
"zh:cab0e1e72c9cebcf669fc6f35ec28cb8ab2dffb0237afc8860aa40d23bf8a49f",
"zh:e523b99a48beec83d9bc04b2d336266044f9f53514cefb652fe6768611847196",
"zh:f593915e8a24829d322d2eaeedcb153328cf9042f0d84f66040dde1be70ede04",
"zh:fba1aff541133e2129dfda0160369635ab48503d5c44b8407ce5922ecc15d0bd",
]
}

33
terraform/main.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
cat <<- 'EOF'
______ _______ _______ _________ _______ _ _______ _______ _________ _______ _______
( __ \ ( ____ \( ____ )\__ __/( ____ \| \ /\ ( )( ___ )|\ /|\__ __/( )( ____ \
| ( \ )| ( \/| ( )| ) ( | ( \/| \ / / | () () || ( ) |( \ / ) ) ( | () () || ( \/
| | ) || (__ | (____)| | | | | | (_/ / | || || || (___) | \ (_) / | | | || || || (__
| | | || __) | __) | | | | | _ ( | |(_)| || ___ | ) _ ( | | | |(_)| || __)
| | ) || ( | (\ ( | | | | | ( \ \ | | | || ( ) | / ( ) \ | | | | | || (
| (__/ )| (____/\| ) \ \_____) (___| (____/\| / \ \ | ) ( || ) ( |( / \ )___) (___| ) ( || (____/\
(______/ (_______/|/ \__/\_______/(_______/|_/ \/ |/ \||/ \||/ \|\_______/|/ \|(_______/
EOF
echo "--- Installation de Terraform sur la machine locale ---"
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
wget -O- https://apt.releases.hashicorp.com/gpg | \
sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list
# Installation finale
sudo apt-get update && sudo apt-get install -y terraform
echo "--- Vérification de l'installation ---"
terraform -version

46
terraform/main.tf Normal file
View File

@@ -0,0 +1,46 @@
terraform {
required_version = ">= 1.0"
required_providers {
proxmox = {
source = "telmate/proxmox"
version = ">= 2.9.14"
}
}
}
provider "proxmox" {
pm_api_url = var.proxmox_api_url
pm_api_token_id = var.proxmox_api_token_id
pm_api_token_secret = var.proxmox_api_token_secret
}
resource "proxmox_lxc" "loustique_lxc" {
target_node = "derick"
hostname = "web-test-terraform"
vmid = 301
ostemplate = "local:vztmpl/ubuntu-24.04-standard_24.04-2_amd64.tar.zst"
password = "wolaouais"
unprivileged = true
cores = 1
memory = 512
rootfs {
storage = "local-lvm"
size = "8G"
}
network {
name = "eth0"
bridge = "vmbr0"
#tag = "2"
ip = "dhcp"
}
}

BIN
terraform/plan.out Normal file

Binary file not shown.

32
terraform/run_terraform.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
cat <<- 'EOF'
______ _______ _______ _________ _______ _ _______ _______ _________ _______ _______
( __ \ ( ____ \( ____ )\__ __/( ____ \| \ /\ ( )( ___ )|\ /|\__ __/( )( ____ \
| ( \ )| ( \/| ( )| ) ( | ( \/| \ / / | () () || ( ) |( \ / ) ) ( | () () || ( \/
| | ) || (__ | (____)| | | | | | (_/ / | || || || (___) | \ (_) / | | | || || || (__
| | | || __) | __) | | | | | _ ( | |(_)| || ___ | ) _ ( | | | |(_)| || __)
| | ) || ( | (\ ( | | | | | ( \ \ | | | || ( ) | / ( ) \ | | | | | || (
| (__/ )| (____/\| ) \ \_____) (___| (____/\| / \ \ | ) ( || ) ( |( / \ )___) (___| ) ( || (____/\
(______/ (_______/|/ \__/\_______/(_______/|_/ \/ |/ \||/ \||/ \|\_______/|/ \|(_______/
EOF
VARS="terraform.tfvars"
echo " Initialisation de Terraform "
terraform init
echo " Vérification du plan "
terraform plan -var-file="$VARS" -out=plan.out
read -p "Voulez-vous appliquer ces changements sur Proxmox ? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo " Déploiement en cours"
terraform apply "plan.out"
else
echo "Déploiement annulé "
fi

12
terraform/variables.tf Normal file
View File

@@ -0,0 +1,12 @@
variable "proxmox_api_url" {
type = string
}
variable "proxmox_api_token_id" {
type = string
}
variable "proxmox_api_token_secret" {
type = string
sensitive = true
}