initialisation

This commit is contained in:
root 2025-09-04 21:18:22 +00:00
parent 0215f3e562
commit 13ad937c30
8 changed files with 229 additions and 0 deletions

0
README.md Normal file
View File

30
lxc.tf Normal file
View File

@ -0,0 +1,30 @@
resource "proxmox_lxc" "container" {
for_each = var.containers
hostname = each.key
target_node = var.target_node
ostemplate = lookup(var.lxc_templates, each.value.template, each.value.template)
unprivileged = each.value.privileged != true
cores = each.value.cores
memory = each.value.memory
swap = 512
password = var.lxcrootPass
rootfs {
storage = var.default_storage
size = each.value.disk_size
}
network {
name = "eth0"
bridge = var.default_bridge
tag = each.value.vlan_tag
ip = each.value.ip
gw = var.default_gateway
}
nameserver = var.dns_servers
onboot = true
start = true
}

9
output.tf Normal file
View File

@ -0,0 +1,9 @@
output "summary" {
description = "Résumé de l'infrastructure"
value = {
node = var.target_node
total_vms = length(var.vms)
total_lxc = length(var.containers)
}
}

6
provider.tf Normal file
View File

@ -0,0 +1,6 @@
provider "proxmox" {
pm_api_url = var.proxmox_url
pm_api_token_id = var.proxmox_token_id
pm_api_token_secret = var.proxmox_token_secret
pm_tls_insecure = var.proxmox_insecure_tls
}

95
variables.tf Normal file
View File

@ -0,0 +1,95 @@
variable "proxmox_url" {
description = "URL de l'API Proxmox"
type = string
default = "https://proxmox.firewax.fr/api2/json"
}
variable "proxmox_token_id" {
description = "token ID"
type = string
sensitive = true
}
variable "proxmox_token_secret" {
description = "secret Token"
type = string
sensitive = true
}
variable "proxmox_insecure_tls" {
description = "Ignorer les erreurs de certificat SSL"
type = bool
default = true
}
variable "target_node" {
description = "Nom du nœud Proxmox"
type = string
default = "pve"
}
variable "default_storage" {
description = "Storage par défaut pour les disques"
type = string
default = "local"
}
variable "default_bridge" {
description = "Bridge réseau par défaut"
type = string
default = "vmbr0"
}
variable "default_gateway" {
description = "Passerelle par défaut"
type = string
}
variable "dns_servers" {
description = "Serveurs DNS"
type = string
default = "8.8.8.8 8.8.4.4"
}
variable "vms" {
description = "Configuration des machines virtuelles"
type = map(object({
cores = number
memory = number
disk_size = string
ip = string
vlan_tag = optional(number)
template = optional(string)
}))
default = {}
}
variable "lxc_templates" {
description = "Templates disponibles pour les containers"
type = map(string)
default = {
ubuntu = "local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst"
debian = "local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst"
}
}
variable "containers" {
description = "Configuration des containers LXC"
type = map(object({
template = string
cores = number
memory = number
disk_size = string
ip = string
vlan_tag = optional(number)
privileged = optional(bool)
enable_docker = optional(bool)
}))
default = {}
}
variable "lxcrootPass" {
description = "mot de passe"
type = string
sensitive = true
}

8
versions.tf Normal file
View File

@ -0,0 +1,8 @@
terraform {
required_providers {
proxmox = {
source = "Telmate/proxmox"
version = "3.0.1-rc9"
}
}
}

39
vm.tf Normal file
View File

@ -0,0 +1,39 @@
resource "proxmox_vm_qemu" "vms" {
for_each = var.vms
name = each.key
target_node = var.target_node
clone = each.value.clone != null ? each.value.clone : null
cores = each.value.cores
sockets = 1
memory = each.value.memory
disks {
ide {
ide0 {
disk {
size = each.value.disk_size
storage = "local-lvm"
}
}
}
}
network {
id = 0
model = "virtio"
bridge = var.default_bridge
tag = each.value.vlan_tag
}
os_type = "cloud-init"
ipconfig0 = "ip=${each.value.ip_address},gw=${var.default_gateway}"
boot = "order=ide0"
tags = "terraform,vm,${each.key}"
}

42
vm.tf.save Normal file
View File

@ -0,0 +1,42 @@
resource "proxmox_vm_qemu" "vms" {
for_each = var.vms
name = each.key
target_node = var.target_node
clone = each.value.clone != null ? each.value.clone : null
cores = each.value.cores
sockets = 1
memory = each.value.memory
disks {
ide {
ide0 {
disk {
size = each.value.disk_size
storage = "local"
}
}
}
}
network {
id = 0
model = "virtio"
bridge = var.default_bridge
tag = each.value.vlan_tag
}
os_type = "cloud-init"
ipconfig0 = "ip=${each.value.ip_address},gw=${var.default_gateway}"
boot = "order=ide0"
tags = "terraform,vm,${each.key}"
}