Distribute VMs over Proxmox machines

zot
Daniel Ankers 2023-10-06 17:26:48 +01:00
parent dce989b822
commit ea6d1bfc09
2 changed files with 15 additions and 4 deletions

11
main.tf
View File

@ -20,6 +20,7 @@ terraform {
source = "techBeck03/guacamole" source = "techBeck03/guacamole"
version = "~> 1.4.1" version = "~> 1.4.1"
} }
} }
backend "kubernetes" { backend "kubernetes" {
secret_suffix = "tfstate" secret_suffix = "tfstate"
@ -396,10 +397,16 @@ EOT
] ]
} }
resource "random_integer" "proxmox_node" {
min=1
max=2
count=var.num_routers
}
resource "proxmox_vm_qemu" "vyos_router" { resource "proxmox_vm_qemu" "vyos_router" {
count = 3 count = var.num_routers
name = "vyos-${count.index + 1}" #count.index starts at 0, so + 1 means this VM will be named test-vm-1 in proxmox name = "vyos-${count.index + 1}" #count.index starts at 0, so + 1 means this VM will be named test-vm-1 in proxmox
target_node = var.proxmox_host target_node = "${var.proxmox_host_prefix}${random_integer.proxmox_node[count.index].result}"
clone = var.vyos_template_name clone = var.vyos_template_name
agent = 1 agent = 1
os_type = "cloud-init" os_type = "cloud-init"

View File

@ -65,8 +65,12 @@ variable "ssh_key" {
EOT EOT
} }
variable "proxmox_host" { variable "proxmox_host_prefix" {
default = "px1" default = "px"
}
variable "num_routers" {
default = "3"
} }
variable "template_name" { variable "template_name" {