first commit
This commit is contained in:
75
terraform/prod/02-monitoring-services.tf
Normal file
75
terraform/prod/02-monitoring-services.tf
Normal file
@@ -0,0 +1,75 @@
|
||||
# Fichier: terraform/environments/prod/02-monitoring-services.tf
|
||||
|
||||
# 1. On cherche TOUS les templates disponibles sur le noeud Proxmox
|
||||
data "proxmox_virtual_environment_vms" "all_templates" {
|
||||
node_name = var.target_node
|
||||
tags = ["template"] # On suppose que tous tes templates ont le tag "template"
|
||||
}
|
||||
|
||||
# 2. On transforme la liste de templates en une map pratique pour les retrouver par OS
|
||||
locals {
|
||||
# Liste des tags d'OS que nous utilisons
|
||||
known_os_tags = toset(["ubuntu", "alpine", "rocky", "debian"])
|
||||
|
||||
# Crée une map du type : { "ubuntu" = { vm_id = 101, name = "ubuntu-..." }, "alpine" = { ... } }
|
||||
template_map = {
|
||||
for t in data.proxmox_virtual_environment_vms.all_templates.vms :
|
||||
one(setintersection(local.known_os_tags, t.tags)) => t
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# 3. On crée nos VMs en utilisant la syntaxe correcte
|
||||
resource "proxmox_virtual_environment_vm" "monitoring_vms" {
|
||||
for_each = var.monitoring_vms
|
||||
|
||||
name = "${each.key}.lab.home.arnodo.fr"
|
||||
node_name = var.target_node
|
||||
tags = ["terraform-managed", "monitoring", each.value.os]
|
||||
on_boot = true
|
||||
|
||||
agent {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
cpu {
|
||||
cores = each.value.cores
|
||||
type = lookup(each.value, "cpu_type", "qemu64")
|
||||
}
|
||||
|
||||
memory {
|
||||
dedicated = each.value.memory
|
||||
}
|
||||
|
||||
disk {
|
||||
interface = "scsi0"
|
||||
datastore_id = "local-lvm"
|
||||
size = each.value.disk_gb
|
||||
}
|
||||
|
||||
network_device {
|
||||
bridge = "vmbr0"
|
||||
model = "virtio"
|
||||
}
|
||||
|
||||
# Bloc de clonage utilisant l'ID du template trouvé dynamiquement
|
||||
clone {
|
||||
vm_id = local.template_map[each.value.os].vm_id
|
||||
}
|
||||
|
||||
# Bloc d'initialisation (Cloud-Init) simplifié
|
||||
initialization {
|
||||
# Configuration réseau
|
||||
ip_config {
|
||||
ipv4 {
|
||||
address = "${each.value.ip}/24"
|
||||
gateway = each.value.gateway
|
||||
}
|
||||
}
|
||||
# Configuration de l'utilisateur
|
||||
user_account {
|
||||
username = "damien" # Ou un autre utilisateur par défaut
|
||||
keys = [file(var.admin_ssh_public_key_path)]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user