DEV Community

Cover image for Proxmox VMs with Terraform (with or without cloud-init)
Mili Cardenas
Mili Cardenas

Posted on

Proxmox VMs with Terraform (with or without cloud-init)

If you run a homelab on Proxmox VE, you probably know the drill: you need "just one quick VM" to test something, and twenty minutes later you're still clicking through the UI — pick the template, set the disk, set the network, wait, SSH in, create a user, install a package... for a VM you might tear down tomorrow.

That friction is what pushed me to write a small Terraform module that clones a VM template and, optionally, applies a custom cloud-init (users, packages, runcmd) rendered from .tftpl files. Nothing fancy — just enough to turn "let me spin up a VM" back into a one-command thing.

What it does:

  • Uses the bpg/proxmox provider.
  • Cloud-init is opt-in — clone-only by default, one line to switch it on when you actually need custom setup.
  • Templates in cloud-init/*.tftpl accept custom variables via an extra map, so the same base template can serve different VM roles (there's a web.yaml.tftpl example that installs nginx).
  • Outputs the VM's IP via the QEMU guest agent once it boots, so you're not hunting for it in the Proxmox UI.
cp terraform.tfvars.example terraform.tfvars
terraform init
terraform plan -out plans/test1.tfplan
terraform apply plans/test1.tfplan
Enter fullscreen mode Exit fullscreen mode

Repo (with setup steps and the exact Proxmox API token permissions you'll need): https://github.com/milyzc/proxmox-terraform-vms

If you're in the same boat — homelab, Proxmox, tired of the manual dance — I'd genuinely love feedback or PRs. It's a small project today, but happy to grow it (multi-VM, more distros) if it's useful to others too.

Top comments (0)