From 4ccb20b3c0d937ef68157abcd3e6264adeff6659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Limpinho?= <53994778+TomasLimpinho@users.noreply.github.com> Date: Tue, 26 Aug 2025 14:17:45 +0100 Subject: [PATCH] multiple vms --- proxmox.tf | 78 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/proxmox.tf b/proxmox.tf index d120a4f..e39e13a 100644 --- a/proxmox.tf +++ b/proxmox.tf @@ -86,11 +86,11 @@ resource "proxmox_virtual_environment_vm" "proxmox-kubernetes-VM-template" { } # Configuração do disco rígido - disk { - datastore_id = "local-lvm" - interface = "scsi1" - size = 64 - } + #disk { + # datastore_id = "local-lvm" + # interface = "scsi1" + # size = 64 + #} disk { datastore_id = "local-lvm" @@ -116,14 +116,76 @@ initialization { } -resource "proxmox_virtual_environment_vm" "VM-Kubernetes-01" { +resource "proxmox_virtual_environment_vm" "k8s_vms" { + for_each = { for vm in var.proxmox_k8s_vms : vm.name => vm } depends_on = [proxmox_virtual_environment_vm.proxmox-kubernetes-VM-template] - name = "VM-Kubernetes-01" - node_name = "fenix" + name = each.value.name + node_name = each.value.node_name + vm_id = each.value.vm_id + + cpu { + cores = each.value.cores + } + + memory { + dedicated = each.value.memory + } + + disk { + datastore_id = each.value.datastore + size = each.value.disk_size + interface = "scsi1" + } clone { vm_id = proxmox_virtual_environment_vm.proxmox-kubernetes-VM-template.id } + + + initialization { + ip_config { + ipv4 { + address = each.value.ip + gateway = each.value.gateway + } + } + + user_data = < 0 ~} + + %{ for u in each.value.extra_users ~} + - name: ${u.name} + groups: [${join(", ", u.groups)}] + shell: /bin/bash + sudo: ALL=(ALL) NOPASSWD:ALL + %{ endfor ~} + + chpasswd: + list: | + %{ for u in each.value.extra_users ~} + ${u.name}:${u.password} + %{ endfor ~} + expire: false + + %{ endif ~} + runcmd: + %{ if length(each.value.extra_runcmd) > 0 ~} + %{ for cmd in each.value.extra_runcmd ~} + - ${cmd} + %{ endfor ~} + %{ endif ~} + EOF + } + + agent { enabled = true }