Skip to main content
  1. Posts/
  2. Terraform./

Automatically Deploying Multiple Virtual Machines in Proxmox 9.0.3 Using Terraform in Docker

··187 words·1 min· loading · loading · ·
Stilicho2011
Author
Stilicho2011
Writing about homelab, self-hosting, automation and open-source solutions
Proxmox Automation - This article is part of a series.
Part : This Article

Below is the file I used in the video, covering how to set up and deploy three virtual machines at once using Terraform.

variable vm_configs {
  type = map(object({
      vm_id = number
      name = string
      cores = number
      memory = number
      vm_state = string 
  }))
  default = {
      "youtube-1" = { vm_id = 357, name = "youtube-1", cores = 1, memory = 2048, vm_state = "stopped"}
      "youtube-2" = { vm_id = 358, name = "youtube-2", cores = 1, memory = 4096, vm_state = "stopped"}   
      "youtube-3" = { vm_id = 359, name = "youtube-3", cores = 1, memory = 2048, vm_state = "running"}
  }
}

resource "proxmox_vm_qemu" "youtubetestvms" {
  for_each = var.vm_configs
  vmid        = each.value.vm_id
  name        = each.value.name
  target_node = "belisarius"
  clone       = "ubuntutemplate"
  full_clone  = true
  bios        = "ovmf"
  agent       = 1 
  scsihw      = "virtio-scsi-single"
  os_type     = "ubuntu"
  cpu_type    = "x86-64-v2-AES"
  cores       = each.value.cores
  sockets     = 1
  memory      = each.value.memory 

  vm_state = each.value.vm_state


  disks {
    scsi {
      scsi0 {
        disk {
          size    = "32G"
          storage = "local"
          format  = "qcow2"
        }
      }
    }
  }

  network {
    id     = 0
    model  = "virtio"
    bridge = "vmbr0"
  }
}
Proxmox Automation - This article is part of a series.
Part : This Article

Related

Nextcloud in Proxmox: A Full Installation in an LXC without Docker

··3335 words·16 mins· loading · loading
A detailed guide to installing and configuring Nextcloud in an LXC container - MariaDB as shown in the video (with an external PostgreSQL option), optional data on an NFS share, PHP-FPM/OPCache/APCu/Redis, live updates via notify_push, and the Memories photo gallery with video transcoding.