Terraform and OpenTofu for Proxmox VE

Provision Proxmox VE virtual machines, containers and networks as code with OpenTofu and the community bpg provider, with the token, state and provider limits planned up front.

On this page

Using Terraform or OpenTofu with Proxmox VE: what the integration does

A team that wants Proxmox VE guests defined in version control instead of clicked through the web UI needs a tool that reads declarative configuration and applies it through the platform's API. OpenTofu, a drop-in replacement for Terraform, drives the Proxmox VE REST API through the community bpg provider. The same provider also works with Terraform, so the choice between the two tools is mostly a question of licensing, governance and what your team already runs. OpenTofu is licensed under the Mozilla Public License 2.0 and is stewarded by the Linux Foundation, while Proxmox VE itself is licensed under the GNU Affero General Public License, version 3. Those are separate components, and your review should cover each one on its own terms.

The bpg provider is third-party software. It is not written or supported by Proxmox Server Solutions, so its release cycle, feature coverage and bug fixes belong to its own maintainers. In practice, the integration covers virtual machine definitions (including disks, network devices and cloud-init settings), LXC containers, and network definitions where the provider exposes them. Before committing to it, check that the provider version you pin supports every resource type and attribute your guests need, and confirm the Proxmox VE version you run is in the provider's tested matrix. Proxmox VE 9.x is the current major line, so verify the provider release notes against the exact version in your cluster before you write the first module.

The practical decision is which API identity Tofu will use and how much of the estate it owns. Plan a dedicated Proxmox VE user with a scoped API token rather than a root login, and decide early which VM IDs, storage pools and bridges the code may touch, so that changes made by hand in the web UI are either blocked or detected. Keep in mind that drift between code and cluster is the most common source of surprises. Confirm with your own environment which resources will be managed as code from day one and which will stay outside the state file.

What you need before the first plan

Most failed first plans trace back to a missing prerequisite rather than a bad configuration. The cards below cover the Proxmox VE release, API access, repository tier, OpenTofu version, images, addressing and state storage, in the order a team usually needs to settle them. Check each one before writing the first resource block.

Supported Proxmox VE release

Start from a 9.x release. Proxmox VE 9.0 was released on August 5, 2025 on Debian 13, 9.1 on November 19, 2025, and 9.2 on May 21, 2026. Confirm the exact version on each node, because provider behavior and API fields can differ between releases. Proxmox VE 8 on Debian 12 has reached end of life, so do not build new automation against it.

Proxmox VE FAQ

API endpoint and token

Confirm that the cluster API is reachable on port 8006 from the machine that runs OpenTofu, and that the TLS certificate is trusted or pinned. Create a dedicated user and an API token for the provider, not a personal login. Grant roles only on the pools, storage and bridges the configuration will touch, and record who owns the token and when it expires.

Least-privilege roles

Map each resource the plan will create, such as VM creation, disk allocation, cloud-init and network attachment, to a Proxmox VE role. Scope those roles to specific storage and pools rather than the root path. Ask the platform owner to review the role set before the first apply, because a broad token is the most common way automation gains more control than intended.

Repository tier decision

The enterprise repository requires a valid subscription key and is the recommended repository for production. The no-subscription repository suits testing and non-production use. Decide which tier each cluster uses before patching, because package versions on the two repositories can diverge and a lab that drifts from production will give misleading plan results.

Package repositories

OpenTofu version pinned

Pin a specific OpenTofu release in your configuration and in CI, for example 1.13.1, which was released on October 1, 2026. Record the version in your repository so every operator runs the same binary. Check the provider version separately, since the community bpg provider has its own release cycle and its own compatibility notes.

OpenTofu releases

Template or cloud-init image

Decide where guest images come from before writing resource blocks. Use a cloud-init-ready template or a cloud image uploaded to a named storage pool, and record its build date and checksum. Confirm that the guest OS supports cloud-init and the guest agent. Without a known image source, the first plan will fail on the disk reference, not on the logic you are testing.

DNS and IP plan

Write down the address ranges, gateway, VLAN IDs and DNS zones for each guest before the first apply. Decide whether addresses are static in cloud-init or assigned by DHCP and reserved. Agree who owns the IPAM record, because Terraform will create guests faster than a manual inventory can track them, and duplicate addresses are hard to spot after the fact.

State backend location

Choose where state lives before the first apply, and who can read it. State contains resource attributes and may contain sensitive values, so decide on an encrypted backend with access control and locking. OpenTofu can encrypt state and plan files at rest, with key providers such as PBKDF2, AWS KMS and OpenBao. Confirm the key provider and recovery process with your security team first.

State encryption docs

How to configure the bpg provider and first apply

This sequence takes a workstation or CI runner from an empty OpenTofu configuration to one managed test VM, one container and one network on a Proxmox VE cluster. Each step ends with a check, so the team knows the foundation holds before it adds more resources.

  1. Install OpenTofu and pin its version

    The platform or infrastructure engineer installs the OpenTofu CLI on the workstation or CI runner that will run applies, then records the exact version in the configuration so every operator uses the same binary. OpenTofu describes itself as a drop-in replacement for Terraform, but teams moving existing code should still confirm which provider versions their configuration needs. Done when tofu version prints the pinned version on every machine that will run the configuration.

  2. Create a scoped API token

    The Proxmox VE administrator creates a dedicated service user in a realm the team controls and grants it only the roles and paths the configuration needs, such as specific pools, storage and nodes. The administrator then creates an API token for that user with privilege separation enabled, so the token carries its own permission set. Store the token secret in the team's secrets manager at creation, because the secret is shown once. Done when a test API call with the token succeeds on an intended path and fails on an out-of-scope path.

  3. Declare the provider and endpoint

    The engineer adds the bpg Proxmox provider to the required providers block, sets a version constraint, and points the provider at the cluster API endpoint. For a lab that uses a private certificate authority, the team installs that CA on the runner so TLS verification stays on. If the team uses the provider's insecure option during a short test, it should record that choice and remove it afterward. Confirm endpoint and TLS settings in the provider documentation for the version you pin. Done when tofu init downloads the provider and tofu validate reports the configuration as valid.

  4. Keep variables and secrets out of code

    The engineer declares the endpoint, node name, storage pool and bridge as input variables, marks the API token as sensitive, and supplies it through environment variables or the secrets manager. The repository should never contain the token, and no committed variable file should hold it. State can contain sensitive values, so the team sets up a remote backend with access control and decides whether to enable OpenTofu's state encryption and which key provider to use. Done when a secret scan of the repository finds no token and tofu plan runs with values supplied only from the environment.

  5. Run init and a read-only plan

    The engineer runs tofu init to set up the backend and providers, then runs tofu plan against the live cluster before the configuration declares any resources. This plan should only read: it confirms the provider reaches the API and returns the nodes, storage and existing guests the team expects. A plan that proposes changes to guests the configuration does not mention usually points to a wrong endpoint, a wrong node name or a state file that does not match the cluster. Done when the plan shows no unexpected changes and the data sources return the expected nodes and storage.

  6. Create one test VM from a template

    The platform team confirms that a cloud-init template exists in Proxmox VE with the QEMU guest agent installed and a cloud-init drive configured, or builds one first. The configuration then clones that template into a single test VM with defined CPU, memory, disk, network bridge and a cloud-init user block that carries an SSH public key. Keep the first apply to this one resource so the blast radius stays small. Done when tofu apply completes and the VM appears in the Proxmox VE web interface with the settings in the configuration.

  7. Verify the guest reports its address

    The engineer starts the VM and checks that it boots, that cloud-init completes and that the QEMU guest agent runs inside the guest. The agent should report an address on the expected network, which the team can also check in the VM's status in Proxmox VE. The engineer then logs in over SSH with the injected key and reviews the console output for cloud-init errors. Confirm the provider attribute for the address against the documentation for the pinned version. Done when the agent reports the address, SSH works with the injected key and the console shows no cloud-init failures.

  8. Add containers and networks in small changes

    The engineer extends the configuration one resource type at a time, starting with an LXC container built from a template confirmed to exist in the target storage pool. Next comes the bridge or VLAN configuration the container uses. Each change gets its own plan review and apply, since network changes can interrupt guests that share the same bridge. The test VM stays in place until all additions verify. Done when the plan shows only the intended additions, the container starts and the network change leaves the test VM reachable.

How cloud-init and state handling fit into the code

Cloud-init settings reach a Proxmox VE guest through the provider's VM resource, and the state file is where OpenTofu remembers what it built. In a typical bpg provider configuration, the initialization block carries IP configuration, DNS, the default user and SSH public keys, while custom user data and vendor data are usually written as snippets and referenced by file ID. Snippets are files, not API fields, so the storage that holds them must have the snippets content type enabled and be reachable from every node that may start the guest. Confirm that storage type with your platform team before the first apply, because a missing snippet storage fails at plan or apply time in a way that looks like a provider bug.

Drift is the main operational risk. Any change made in the web UI, through qm on a node, or by an Ansible role that edits guest configuration will show up as a diff on the next plan. Decide before rollout which tool owns each attribute, such as network and disk sizing in OpenTofu and post-boot configuration in Ansible, and make the code match reality with a refresh-and-plan review rather than overwriting manual changes blindly. Keep state in a remote backend with locking so two pipelines cannot apply at once, and note that a lost or corrupted state file means re-importing existing guests.

OpenTofu encrypts state and plan files at rest, for local storage and remote backends, and introduced this in v1.7. The supported key providers are PBKDF2, AWS KMS, GCP KMS, OpenBao and Azure Vault. Choose the provider based on where your existing key management lives: a passphrase-derived key via PBKDF2 needs a secure process for storing the passphrase, while a cloud KMS or OpenBao adds an external dependency that the pipeline must reach. Confirm the chosen provider against the OpenTofu state encryption documentation and test a restore from an encrypted backup before relying on it.

Mapping Proxmox VE objects to code resources

This table maps the Proxmox VE objects you will manage (nodes, VM IDs, pools, storage, bridges, API tokens, cloud-init and container mounts) to the resources and variables that hold them in the community bpg provider. Read each row as a checklist: set the attribute explicitly when it defines identity or placement, inherit it when a template owns it, and keep the secret values out of the repository.

Proxmox VE objectWhere it lives in codeSet explicitly or inherit, and secret handling
NodeNode name in the resource node_name argument; a variable such as pve_node selects the hostSet explicitly. A wrong node name fails at apply time, so confirm names with the cluster before writing modules.
VM IDvm_id on a VM resource; keep the ID range in a variable map keyed by environment or roleSet explicitly. Plan IDs ahead so reruns do not collide with guests created outside code.
Resource poolpool_id on the VM or container resource, with the pool itself managed as a separate resourceSet explicitly if your permission model depends on pools. Confirm pool support in your provider version.
Storagedatastore_id on disks and the cloud-init drive; variables hold the storage name such as a local ZFS or Ceph poolSet explicitly per disk. Storage names differ between clusters, so keep them in per-environment variable files.
Bridge and VLANbridge and vlan_id inside a network device block; the bridge must already exist on the nodeSet explicitly. The provider does not create host bridges in most setups, so confirm the bridge with the host configuration first.
API token and roleProvider endpoint and api_token arguments; the token role is granted in Proxmox VE, not in codeSecret. Store the token value in a secret manager or CI variable, and scope the token to the minimum permissions the pipeline needs.
Cloud-init settingsinitialization block with user account, SSH keys, IP configuration and DNS settingsPartly inherited. The template usually provides the guest agent and base packages; set user and network per guest. SSH public keys are not secret, but passwords are.
Container template and mount pointContainer resource operating_system for the template and mount_point blocks for storage volumesSet the template reference explicitly. Mount points must match storage that exists on the target node, so confirm volume names before apply.
Clone source and templateclone block referencing a template VM ID and datastoreInherited from the template. Changes to the template do not update existing guests, so version template IDs deliberately.

Securing the API token, state and provider code

Terraform and OpenTofu for Proxmox VE hold credentials that can create, change and destroy guests across a cluster, and the state they write can expose secrets in plain text. The cards below cover who holds those credentials, how the connection is verified, how changes are approved, and how the provider code that runs against your hypervisor is pinned and reviewed.

Scoped API tokens, not user passwords

Give the provider a dedicated API token tied to a service account with only the roles the configuration needs, rather than a personal admin login with a password. Scope the token's privileges to the pools, storage and nodes it manages, and keep the token secret out of .tf files and version control. Check that the token can be revoked without disrupting human access, and that its permissions are reviewed when the configuration grows. Token and permission design is covered in Proxmox VE hardening.

User management docs

TLS verification of the endpoint

The provider talks to the Proxmox VE API over HTTPS, and disabling certificate verification to get a first apply working is a common shortcut that leaves the API token exposed to interception. Install the cluster certificate or an internal CA chain on the machine that runs Terraform or OpenTofu, and keep verification enabled in every pipeline. Confirm the endpoint name in the configuration matches the certificate subject so that verification failures are real signals.

Restricting who can run apply

A plan is read-only, but an apply can delete production guests, so separate the two permissions. Run plan on merge requests for review and limit apply to a protected branch, a named approver group, or a pipeline environment that requires sign-off. Make sure the runner that holds the API token is not reachable by every developer who can push code. Record who approved each apply so that changes to guest configuration can be traced.

Protecting state that holds secrets

State files record resource attributes, and some of those attributes can include cloud-init passwords, SSH keys and token-derived values. Store state in a remote backend with access control, encryption at rest and versioning, and do not commit terraform.tfstate to Git. OpenTofu can encrypt state and plan files with key providers such as AWS KMS or OpenBao, and the state encryption documentation sets out the options. Restrict who can read state separately from who can write it.

Encryption introduced
v1.7
State encryption docs

Pinning provider and tool versions

Lock the bpg Proxmox provider and the OpenTofu or Terraform binary to specific versions, and commit the dependency lock file so every run resolves the same provider build. Upgrade both on purpose, in a branch that runs plan against a test cluster first, since provider changes can alter how an existing guest attribute is read. Record the versions used in your pipeline image so that an audit can reproduce a past run.

Reviewing third-party provider code

The bpg provider is a community project, not a Proxmox Server Solutions product, so its maintainers, release cadence and open issues are part of your risk assessment. Read the changelog before each upgrade, check how quickly security issues and breaking changes are fixed, and review the provider's handling of credentials and TLS in the code you rely on. Decide in advance who owns a fork or pinned fallback if the project slows down, and confirm this with the provider's repository before you commit to it.

Two-factor on admin accounts that create tokens

Whoever creates an API token can usually grant it the same reach as the account that made it, so the human admin accounts that generate tokens need strong authentication. Enable a second factor such as TOTP or WebAuthn on those accounts, keep recovery keys in a controlled location, and limit how many people hold the rights to create tokens. Review the list of tokens periodically and remove any that belong to people who have left or to pipelines that were retired.

User management docs

Common failures when provisioning with the bpg provider

This table lists the failures teams most often hit when provisioning Proxmox VE guests with the bpg provider, with the usual cause and the fix for each. Read it as a checklist to work through before changing code, since several symptoms (such as auth errors and clone failures) share the same underlying privilege or storage problem. The main takeaway is that most failures come from token scope, endpoint trust, storage permissions or state handling, and each one is diagnosable from the plan output and the Proxmox VE task log.

FailureCauseFix
Authentication failsAPI token ID written in the wrong format, or the token's user lacks the privileges the plan needs on the target nodes, storage and poolUse the full user@realm!tokenid form in the provider configuration, then grant the token role-based access on the paths the plan touches and confirm with a read-only plan first
Certificate errors on the API endpointThe Proxmox VE node presents a self-signed or internally issued certificate that the OpenTofu host does not trustInstall the internal CA on the workstation or runner, or set the provider's insecure option only as a temporary test step and document the exception
Clone failsThe source template VM ID does not exist on the target node, or the token cannot read the template or write to the target storageConfirm the template is on the node named in the plan, check that the token has access to both the source and destination storage, and verify the template is marked as a template
Cloud-init settings not appliedA snippet file the configuration references is missing from the snippets storage, or the guest agent is not running in the image so the provider cannot read the IP addressUpload the snippet to a storage that allows snippets, confirm the file name matches the configuration, and install and enable the QEMU guest agent in the template before cloning
Plan shows drift after manual changesSomeone edited the VM in the web UI or through the API, so the live configuration no longer matches the state fileReview the diff, then either bring the change into code and apply, or revert it in the UI. Agree a rule that the web UI is read-only for managed guests
State lock or lost stateA previous run was interrupted and left a lock, or the state file was stored only on one laptop or deleted by mistakeConfirm no other run is active before forcing an unlock, restore state from the remote backup, and store state in a shared backend with versioning and encryption
Provider or OpenTofu version mismatchThe provider version was upgraded without matching the OpenTofu version or the Proxmox VE API behavior, so resource arguments change or failPin the OpenTofu and provider versions in the configuration and lock file, read the provider changelog before upgrading, and test the upgrade on a non-production cluster first

Limits of a third-party provider and what to verify

The bpg Proxmox provider is community maintained, not an official Proxmox VE product, so its coverage of the Proxmox VE API trails the API itself. A new endpoint, a new option on an existing resource or a recent storage or SDN behavior may be missing from the provider, or exposed only in a later release. Before you design a module around a feature, check the provider's resource documentation and its changelog for that feature, and confirm the argument names against the API viewer on your own cluster. Where the provider has no resource or data source for an operation, plan to use the Proxmox VE API directly through a local-exec step, or hand that task to Ansible with the community.proxmox collection, and record which tool owns which object so two tools do not fight over the same guest. Also confirm how the provider handles drift on fields it does not model, because a change made in the web interface can be silently reverted by the next apply.

OpenTofu is designed as a drop-in replacement for Terraform, and the OpenTofu FAQ states an aim of feature parity with Terraform. The same FAQ is explicit that compatibility with future Terraform releases is not guaranteed, because the OpenTofu community decides which features it adopts. Treat the Terraform or OpenTofu version and the provider version as one locked set. Pin both in your configuration, commit the dependency lock file, and record the exact OpenTofu release in your pipeline image. Check the OpenTofu migration overview before any move between tools, and if your configurations use the terraform_remote_state data source, follow the extra steps it describes.

Upgrade in two stages. First, bump the provider or the OpenTofu binary in a non-production Proxmox VE cluster that mirrors the production node count, storage backends and SDN configuration, and run plan against real state copies to read every proposed change. Look especially for replacements, which can destroy and recreate a running guest. Second, promote the same change to production only after the plan is clean and an apply has been tested on a throwaway VM. Keep the previous provider and binary versions available so you can roll back the code and the state together. Ask any partner you engage to show the plan output and the rollback steps for each upgrade, and to name who owns the provider decision when a needed feature is missing.

Questions teams ask before provisioning Proxmox VE as code

What drives the cost of provisioning Proxmox VE with Terraform or OpenTofu?

The cost follows the number of templates, networks, storage pools and cluster nodes the code must describe, plus how many environments need the same definitions. Most of the effort is design and testing rather than writing resource blocks. The main cost components are the engineering time to build the modules, the token and access model, the state backend and its protection, and the review of the first apply against your live cluster. Recurring costs come from maintaining provider version pins, upgrading the provider when Proxmox VE changes, and keeping templates current. Ask any quote to list each of these items separately and state which parts are one-time and which recur.

How long does a first working Proxmox VE setup as code take?

The duration depends mainly on how many VM templates, network segments and storage targets the first version covers, and on how quickly your team approves the token policy and network plan. A single cluster with one template and one bridge is a much smaller job than a multi-site setup with VLAN-aware networks, cloud-init customization and separate environments. Before accepting any timeline, ask the provider or partner to list the resources in the first milestone, the environments they will test against, and the approvals that must happen before the first apply on production hosts.

What does our team need to provide before provisioning starts?

You need to provide access to a non-production Proxmox VE cluster for testing, and a documented decision on how API credentials will be created and scoped. Most teams create a dedicated user and API token with only the privileges the code needs, rather than reusing an administrator account. You also need a network plan with bridges, VLAN IDs, IP address ranges and DNS, the storage pools that guests will use, and a place to keep Terraform or OpenTofu state that is encrypted and access-controlled. Finally, plan for change approvals, because the first run will create and possibly modify live guests.

Can our own team build this in-house?

Yes, a team that already runs Proxmox VE and knows Terraform or OpenTofu can build a working setup in-house, and many do. The skills that matter most are Proxmox VE permissions and API tokens, cloud-init behavior, Linux image preparation, and infrastructure-as-code practice such as module design, state handling and code review. Teams that lack one of these areas often spend most of their time on the parts that cause outages, such as state corruption, over-privileged tokens or template drift. Assess your team against that list, and decide whether a fixed-scope engagement is worth it for the first version, the documentation and the handover.

Should we choose OpenTofu or Terraform for Proxmox VE?

OpenTofu is licensed under the Mozilla Public License 2.0 and describes itself as a drop-in replacement for Terraform that preserves existing workflows and configurations. The project is under the Linux Foundation's stewardship and was accepted to the CNCF at the Sandbox maturity level on April 23, 2025. Its FAQ aims for feature parity with Terraform but does not guarantee compatibility with future Terraform releases. Choose based on licensing, governance and the features you need. If you already run Terraform under the Business Source License, check your legal position first. The migration guide describes a process meant to be safe and reversible, but configurations that use the terraform_remote_state data source need extra care.

Why does the community bpg provider need a risk review?

The bpg provider is a third-party project, not an official Proxmox Server Solutions product, so its release cadence, feature coverage and bug fixes are outside Proxmox's control. Review the provider's maintenance activity, changelog and open issues before adopting it, and pin a specific version so upgrades are deliberate. Confirm which resources and attributes your Proxmox VE version supports, because some features may be missing or behave differently after a Proxmox VE upgrade. Keep a tested fallback, such as manual or API-driven changes, for cases where the provider lags behind a release.

How do we protect Terraform or OpenTofu state for Proxmox VE?

State files often contain sensitive values such as credentials and resource details, so they need protection before the first apply. OpenTofu encrypts state and plan files at rest for local storage and remote backends, with key providers that include PBKDF2, AWS KMS, GCP KMS, OpenBao and Azure Vault, and the feature was introduced in v1.7. Confirm which key provider fits your key management policy, who can read the backend, how locks are enforced, and how state is backed up. Document the recovery steps for a lost or corrupted state file before production use.

What does a fixed-scope engagement for this work cover?

A fixed-scope engagement is agreed in writing before work starts and lists the scope, deliverables and timeline. For this topic, the scope usually includes the provider and version decision, the API token and permission model, the module structure for VMs, containers and networks, cloud-init integration, the state backend design, testing against a non-production cluster, and a handover with documentation. It does not include changes outside the agreed scope, such as template build pipelines or Proxmox VE cluster design, unless those are added to the written scope. Ask for the deliverable list, the acceptance criteria and what happens if the environment differs from the plan.

How the code, state and Proxmox VE API connect

The flow starts in the engineer's repository, where the configuration is written and reviewed. A CI runner or workstation runs OpenTofu with the bpg provider, which reads and writes state through the state backend, where encryption at rest protects the state and plan files. The provider then calls the Proxmox VE API on the cluster, which creates the guest and pulls cloud-init settings or a template from storage. Check where each trust boundary sits, because the API token and the state key are the two credentials that cross it.

Credentials and state cross three separate trust boundaries before a guest exists.

How DeployOpen works on this

DeployOpen plans, implements, documents and supports self-hosted open-source platforms inside your own infrastructure, including Proxmox VE. For Terraform and OpenTofu, we start from the provisioning workflow your team needs, build it against your clusters and state backend, and hand over code and runbooks your engineers can operate.

How we scope

  • Written scope lists the Proxmox VE clusters, node versions and guest types the code will provision.
  • Scope names the provider, the token permissions and the cloud-init inputs agreed with your team.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.

How we build

  • We configure the provider with API tokens and least-privilege roles, rather than shared administrator logins.
  • Modules cover VMs, LXC containers and networks, with templates and cloud-init variables kept in version control.
  • State is placed in a backend you choose, with encryption and locking defined before the first apply.

How we hand over

  • You receive the code repository, module documentation and a state recovery procedure for your team.
  • Test runs against a non-production cluster are documented, including plan output and drift checks.
  • Operators are walked through upgrade steps for the provider and OpenTofu or Terraform versions in use.

How we support

  • Ongoing support, provider upgrades and continuous testing are available as a retainer.
  • Retainer scope should be confirmed in writing, including which provider and Proxmox VE versions it covers.
  • Security testing of the automation pipeline and its credentials can be scoped as a separate engagement.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.