Terraform Proxmox tutorial: create LXC containers on Proxmox VE 9 with an API token
A working Terraform setup for Proxmox VE 9.3: a least-privilege API token from the CLI, the bpg/proxmox provider, and an LXC container you can create and destroy with one command. Rewritten for 2026, no screenshots needed.
Updated November 2026: rewritten for Proxmox VE 9.3 and the bpg/proxmox provider. The original 2022 version used the Telmate provider 2.9 and Proxmox 7.
If you followed the 2022 version of this post, the config won't run on Proxmox VE 9. The Telmate/proxmox 2.9 provider asks for a privilege Proxmox 9 removed, and the token setup told you to turn off privilege separation, which 9.3 can now forbid by policy.
This is the setup I'd use today: an API token created from the command line, the bpg/proxmox provider, and one LXC container that Terraform can create and destroy. Everything is done in the shell, so there are no screenshots to go out of date.
What you need: Proxmox VE 9.x (I wrote this against 9.3), root shell access to the node, and Terraform 1.6+ or OpenTofu 1.6+ on your workstation.
Which Terraform provider to use for Proxmox in 2026
There are two community providers. For a new setup on Proxmox VE 9, use bpg/proxmox.
| bpg/proxmox | Telmate/proxmox | |
|---|---|---|
| Latest version (Nov 2026) | 0.123.1 | 3.0.2-rc10 (release candidate) |
| Proxmox VE 9 | primary target | works from 3.0.2-rc04 |
| Proxmox VE 7 | not supported | supported |
| Release pace | several releases a month | slower, still in RC |
| Covers | VMs, containers, storage, SDN, users, firewall, HA and more | VMs and containers |
Telmate is fine if you already have a large codebase on it and moved to 3.0.2-rc04 or later. Earlier versions fail on Proxmox 9 with a missing VM.Monitor permission, because Proxmox 9 dropped that privilege. For anything new, bpg has the wider coverage and the faster fixes.
Step 1: Create a Terraform user and API token
Run these on the Proxmox node as root. First, a dedicated user. The @pve suffix means it exists only inside Proxmox, so there's no Linux account to manage:
pveum user add terraform@pve --comment "Terraform"
Then create the token. Keep privilege separation on (--privsep 1, the default). With it, the token only gets the permissions you grant to the token itself, and Proxmox VE 9.3 can enforce privilege separation as a cluster-wide token policy, so a --privsep 0 token may not even be allowed on your cluster. I covered that policy in the Proxmox VE 9.3 upgrade checklist.
pveum user token add terraform@pve provider --privsep 1 --comment "Terraform provider"
The output shows full-tokenid (terraform@pve!provider) and value (the secret). Copy the secret now. Proxmox shows it only once.
If you want the token to expire, add --expire with a Unix timestamp, for example 90 days from now:
pveum user token add terraform@pve provider --privsep 1 --expire $(date -d '+90 days' +%s)
Step 2: Give the token the permissions it needs
A privilege-separated token's effective permissions are the intersection of the user's and the token's. So grant the same roles to both.
I use built-in roles instead of a custom privilege list. They're maintained by Proxmox and you can't mistype them (the full list is in the Proxmox user management docs):
pveum acl modify / --users terraform@pve --roles PVEVMAdmin,PVEDatastoreUser,PVESDNUser,PVEAuditor
pveum acl modify / --tokens 'terraform@pve!provider' --roles PVEVMAdmin,PVEDatastoreUser,PVESDNUser,PVEAuditor
What each role is for:
PVEVMAdmin: create, configure, start and delete VMs and containersPVEDatastoreUser: allocate disk space on storages likelocal-lvmPVESDNUser: attach network interfaces to bridges likevmbr0(on Proxmox 9, bridges are checked through SDN permissions)PVEAuditor: read node, storage and cluster status, which the provider needs for planning
Keep the single quotes around terraform@pve!provider. Without them, bash treats ! as history expansion.
Check what the token ended up with:
pveum user token permissions terraform@pve provider
The bpg provider docs show a much longer custom role. That's useful if Terraform manages your whole cluster, users and permissions included. For VMs and containers it's far more than the token needs.
Step 3: Download an LXC template
Terraform can download templates too, but for a first run it's simpler to use one that's already on the node. Refresh the template list and pick an Ubuntu image:
pveam update
pveam available --section system | grep ubuntu
pveam download local ubuntu-24.04-standard_24.04-2_amd64.tar.zst
pveam list local
Use the exact file name from pveam available on your node. The last command prints the volume ID you'll put in Terraform, in the form local:vztmpl/<file name>.
Step 4: Write the Terraform files
Make a new directory with three files. All three are also in the proxmox-terraform-example repo on GitHub if you'd rather clone than copy.
versions.tf pins the provider and configures it:
terraform {
required_version = ">= 1.6"
required_providers {
proxmox = {
source = "bpg/proxmox"
version = "~> 0.123"
}
}
}
provider "proxmox" {
# endpoint and api_token come from environment variables:
# PROXMOX_VE_ENDPOINT and PROXMOX_VE_API_TOKEN
insecure = true # self-signed certificate on a homelab node
}
Next, variables.tf holds what changes between setups:
variable "node_name" {
description = "Proxmox node name, as shown in the web UI"
type = string
default = "pve"
}
variable "template_file_id" {
description = "LXC template volume ID, from 'pveam list local'"
type = string
default = "local:vztmpl/ubuntu-24.04-standard_24.04-2_amd64.tar.zst"
}
variable "ssh_public_key" {
description = "Path to the SSH public key to put into the container"
type = string
default = "~/.ssh/id_ed25519.pub"
}
main.tf is the container itself:
resource "proxmox_virtual_environment_container" "web" {
node_name = var.node_name
vm_id = 210
description = "Managed by Terraform"
tags = ["terraform"]
unprivileged = true
start_on_boot = true
features {
nesting = true # needed by systemd in recent distros
}
operating_system {
template_file_id = var.template_file_id
type = "ubuntu"
}
cpu {
cores = 2
}
memory {
dedicated = 1024
swap = 512
}
disk {
datastore_id = "local-lvm"
size = 8
}
network_interface {
name = "eth0"
bridge = "vmbr0"
}
initialization {
hostname = "web-01"
ip_config {
ipv4 {
address = "dhcp"
}
}
user_account {
keys = [trimspace(file(pathexpand(var.ssh_public_key)))]
}
}
}
output "container_id" {
value = proxmox_virtual_environment_container.web.vm_id
}
Change node_name, datastore_id and bridge if yours differ. On a ZFS install the storage is usually local-zfs instead of local-lvm.
This container is unprivileged on purpose. An API token can't create privileged containers with feature flags, because Proxmox reserves that for root@pam. Unprivileged is the better default anyway.
Step 5: Run it
Put the endpoint and token in environment variables instead of the files. The token string is the token ID and the secret joined with =:
export PROXMOX_VE_ENDPOINT="https://192.168.1.10:8006/"
export PROXMOX_VE_API_TOKEN='terraform@pve!provider=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
Don't add /api2/json to the endpoint. The bpg provider adds it itself, and this is the most common copy-paste mistake from old Telmate configs.
Then the usual three commands:
terraform init
terraform plan
terraform apply
plan should show one resource to add. After apply, container 210 appears in the web UI, starts, and gets an address from DHCP. SSH in with the key you passed:
ssh root@<container-ip>
To remove everything Terraform created:
terraform destroy
Everything above works the same with OpenTofu. Replace terraform with tofu.
Common errors and fixes
Permission check failed or HTTP 403 on apply. The token is missing a privilege. Run pveum user token permissions terraform@pve provider and compare. Remember that with privilege separation, the role has to be on both the user and the token.
changing feature flags for privileged container is only allowed for root@pam. You set unprivileged = false together with feature flags. API tokens can't do that. Keep the container unprivileged, or use password auth as root@pam for that one resource.
TLS handshake error on a fresh node. The bpg provider expects TLS 1.3 by default. If something in front of Proxmox (an old reverse proxy, for example) only speaks TLS 1.2, set min_tls = "1.2" in the provider block.
interface not found for vmbr0. The token can't see the bridge. That's the PVESDNUser role (SDN.Use) missing on Proxmox 9.
terraform plan hangs or times out. Check that port 8006 on the node is reachable from where you run Terraform, and that PROXMOX_VE_ENDPOINT ends with :8006/.
Moving from the old Telmate config
There's no automatic migration. The resource types are different (proxmox_lxc in Telmate, proxmox_virtual_environment_container in bpg), and so are most argument names.
For containers you want to keep, write the bpg resource, then import the existing container instead of recreating it:
terraform import proxmox_virtual_environment_container.web pve/210
The format is <node>/<vmid>. Run terraform plan afterwards and adjust the config until the plan shows no changes. Then remove the old Telmate resource from state with terraform state rm, so Terraform doesn't try to delete the container.
My take
For a homelab, Terraform on Proxmox pays off at the second container, not the first. The win is that terraform destroy and apply give you a clean environment in a minute, and the config doubles as documentation of what's running.
Once containers work, VMs with cloud-init are the natural next step. Install the QEMU guest agent in your template so Terraform and the web UI can see each VM's IP.
Two habits I'd keep from day one: a dedicated token with privilege separation and a narrow role, and credentials in environment variables, never in .tf files you might push to Git.
FAQ
Does Terraform work with Proxmox VE 9?
Yes. The bpg/proxmox provider targets Proxmox VE 9.x as its main platform. The Telmate provider works on Proxmox 9 from version 3.0.2-rc04 onwards. Older Telmate versions fail with a missing VM.Monitor permission.
Should I use Telmate or bpg for Proxmox?
For new projects, bpg/proxmox. It's actively released, covers far more of the Proxmox API, and is built for Proxmox VE 9. Stay on Telmate 3.0.2-rc04 or newer only if you have an existing codebase that's costly to migrate.
Do I need SSH access for the bpg provider?
Not for this tutorial. Creating VMs and containers works entirely through the API. SSH is only needed for a few operations, such as uploading snippets or setting LXC idmap entries.
Can I use OpenTofu instead of Terraform?
Yes. The bpg provider supports OpenTofu 1.6 and newer, and the configuration in this post is identical. Run tofu init, tofu plan and tofu apply instead of the terraform commands.
Should I turn off privilege separation on the API token?
No. Older guides, including the first version of this one, said to disable it. Proxmox VE 9.3 can require privilege separation through a cluster-wide token policy. Keep it on and grant roles to both the user and the token.