From 13ad937c30e19f06117de1bb347aecc9495b8330 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Sep 2025 21:18:22 +0000 Subject: [PATCH] initialisation --- README.md | 0 lxc.tf | 30 +++++++++++++++++ output.tf | 9 +++++ provider.tf | 6 ++++ variables.tf | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ versions.tf | 8 +++++ vm.tf | 39 +++++++++++++++++++++ vm.tf.save | 42 +++++++++++++++++++++++ 8 files changed, 229 insertions(+) create mode 100644 README.md create mode 100644 lxc.tf create mode 100644 output.tf create mode 100644 provider.tf create mode 100644 variables.tf create mode 100644 versions.tf create mode 100644 vm.tf create mode 100644 vm.tf.save diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/lxc.tf b/lxc.tf new file mode 100644 index 0000000..226c729 --- /dev/null +++ b/lxc.tf @@ -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 +} diff --git a/output.tf b/output.tf new file mode 100644 index 0000000..967764a --- /dev/null +++ b/output.tf @@ -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) + } +} diff --git a/provider.tf b/provider.tf new file mode 100644 index 0000000..47224c9 --- /dev/null +++ b/provider.tf @@ -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 +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..5f6d7cb --- /dev/null +++ b/variables.tf @@ -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 +} diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..fadb479 --- /dev/null +++ b/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + proxmox = { + source = "Telmate/proxmox" + version = "3.0.1-rc9" + } + } +} diff --git a/vm.tf b/vm.tf new file mode 100644 index 0000000..76bdcfa --- /dev/null +++ b/vm.tf @@ -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}" +} diff --git a/vm.tf.save b/vm.tf.save new file mode 100644 index 0000000..30a6424 --- /dev/null +++ b/vm.tf.save @@ -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}" +} + + +