Pcornel
Browse topics
Options
Recent
Favorites
Virtualization · Technical reference

Terraform

Direct answer

Terraform provisions VMs declaratively with providers for vSphere, Proxmox, Hyper-V, libvirt and clouds; terraform plan shows what will change, apply makes it so, and the state file tracks what Terraform manages.

When to use this

Use this when provisioning VMs with Terraform or OpenTofu on vSphere, Proxmox, Hyper-V, libvirt or cloud, or when plan and reality disagree.

First 30 seconds

1. Terraform creates VMs declaratively via providers.

2. Remote state with locking.

3. Review plans.

4. Avoid manual changes (drift).

5. Pin provider versions.

Operational verification

HCL → provider → API → VMs → state

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
virtualization
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformvirtualization
Scope / prerequisiteUse this when provisioning VMs with Terraform or OpenTofu on vSphere, Proxmox, Hyper-V, libvirt or cloud, or when plan …
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Checks Verify boundary
terraform init
terraform validate
terraform plan -out=tfplan

Review the plan before apply; destroy plans need extra care.

Step 2 Common mistakes Narrow the fault
  • Different provider versions between team members (commit .terraform.lock.hcl).
  • Changes in the GUI not reflected in code.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • Never edit state by hand without a backup.
  • Changing some attributes forces replace — read the plan.
  • Remote state needs locking.
Key checks
  • terraform init && terraform plan — providers and plan
  • terraform state list — managed resources
  • terraform providers — bpg/proxmox, vsphere, hyperv providers
ReferenceWhy it matters1 section · depth on demand

Providers

PlatformProvider
vSpherehashicorp/vsphere
Proxmoxbpg/proxmox (or telmate/proxmox)
libvirtdmacvicar/libvirt
Hyper-Vtaliesins/hyperv (community)
ReferenceImportant terms & boundaries2 sections · depth on demand

In depth

Terraform/OpenTofu provisions VMs declaratively. Example with the bpg/proxmox provider:

resource "proxmox_virtual_environment_vm" "web" {
  name      = "web01"
  node_name = "pve1"
  clone { vm_id = 9000 }
  cpu    { cores = 2 type = "x86-64-v3" }
  memory { dedicated = 4096 }
  network_device { bridge = "vmbr0" vlan_id = 20 }
  initialization {
    ip_config { ipv4 { address = "10.0.20.11/24" gateway = "10.0.20.1" } }
    user_account { username = "ops" keys = [var.ssh_key] }
  }
}

Pin provider versions, store state remotely with locking, and use lifecycle { ignore_changes = [...] } for attributes changed outside Terraform on purpose.

Example (Proxmox provider)

resource "proxmox_virtual_environment_vm" "web" {
  name      = "web01"
  node_name = "pve1"
  clone { vm_id = 9000 }
  cpu    { cores = 2 }
  memory { dedicated = 4096 }
}

Documented example, not captured output. Run terraform plan before apply and keep state remote with locking.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docvirtualization current

Authoritative/upstream documentation reviewed for bounded claims in Automation → Terraform. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://libvirt.org/html/index.html · confidence 94%
Confirmation

Confirm action

Continue?