Get started with the Proxmox Terraform provider
masterdocs/ directory of this repository, which includes a full list of provider options and guides for configuring specific VM types.repository·master·Indexed 25 days ago
https://github.com/telmate/terraform-provider-proxmoxA Terraform provider for the Proxmox virtualization platform that enables the management of QEMU virtual machines and LXC containers. It supports Cloud-Init configuration via automatic settings or custom snippets (cicustom), fine-grained control over VM CPU, boot, and hotplug options, and provides guides for installation and developer debugging.
docs/ directory of this repository, which includes a full list of provider options and guides for configuring specific VM types.You can enable advanced container features using the features block within the proxmox_lxc resource. Supported features include:
fuse: Boolean to enable FUSE.nesting: Boolean to enable nesting.mount: A string containing semicolon-separated mount types (e.g., nfs;cifs).resource "proxmox_lxc" "advanced_features" {
target_node = "pve"
hostname = "lxc-advanced-features"
ostemplate = "local:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz"
unprivileged = true
ssh_public_keys = <<-EOT
ssh-rsa <public_key_1> user@example.com
ssh-ed25519 <public_key_2> user@example.com
EOT
features {
fuse = true
nesting = true
mount = "nfs;cifs"
}
rootfs {
storage = "local-zfs"
size = "8G"
}
mountpoint {
slot = "0"
storage = "/mnt/host/nfs"
mp = "/mnt/container/nfs"
size = "250G"
}
network {
name = "eth0"
bridge = "vmbr0"
ip = "10.0.0.2/24"
ip6 = "auto"
}
}For older versions of Terraform, plugins should be placed directly into the ~/.terraform.d/plugins directory.
mkdir -p ~/.terraform.d/plugins
cp -f bin/terraform-provider-proxmox ~/.terraform.d/pluginsTo enable Network Boot (PXE), set pxe = true. For a successful PXE boot, ensure the following requirements are met:
boot parameter must include a network type in its order (e.g., order=scsi0;net0).agent = 0 unless the OS installation specifically includes the agent.Note: PXE boot mode requires external infrastructure to support the Network PXE boot request by the VM.
resource "proxmox_vm_qemu" "pxe-minimal-example" {
name = "pxe-minimal-example"
agent = 0
boot = "order=scsi0;net0"
pxe = true
target_node = "test"
network {
id = 0
bridge = "vmbr0"
firewall = false
link_down = false
model = "e1000"
}
}When reporting issues on the issue tracker, follow these steps to ensure your problem can be reproduced quickly:
issue.tf file that recreates your problem. You can do this by taking a minimal working example and adding elements from your original Terraform file until the issue reappears.provider.tf file. You do not need to include vars.tf files.You can import an existing Proxmox VM into your Terraform state using its node, type, and VM ID. The <type> must always be qemu for VM resources.
Command Syntax:
terraform import [options] <RESOURCE_ADDRESS> <node>/qemu/<vmId>Example Workflow: To understand how Proxmox GUI settings map to Terraform configuration:
test.tf) with a dummy resource block:resource "proxmox_vm_qemu" "import_test" { }mynode and VM ID is 106):terraform import proxmox_vm_qemu.import_test mynode/qemu/106terraform.tfstate file to see the imported configuration attributes.terraform import proxmox_vm_qemu.import_test mynode/qemu/106To use Cloud-Init with the Proxmox provider, you must first create a template in the Proxmox Virtual Environment (PVE) shell. This involves downloading a Cloud-Init image, importing it into a VM, and converting that VM into a template.
Note: All commands below must be performed from the PVE shell.
For Terraform versions 0.13 and later, third-party providers must follow a specific filesystem layout using a virtual source registry (e.g., registry.example.com).
linux_amd64 for Linux or darwin_amd64 for macOS.~/.terraform.d/plugins/[host.domain]/telmate/proxmox/[version]/[arch]../bin to the newly created directory.main.tf to use the virtual source address.Example using registry.example.com and version 1.0.0 on Linux:
PLUGIN_ARCH=linux_amd64
mkdir -p ~/.terraform.d/plugins/registry.example.com/telmate/proxmox/1.0.0/${PLUGIN_ARCH}
cp bin/terraform-provider-proxmox ~/.terraform.d/plugins/registry.example.com/telmate/proxmox/1.0.0/${PLUGIN_ARCH}/In your main.tf:
terraform {
required_providers {
proxmox = {
source = "registry.example.com/telmate/proxmox"
version = ">=1.0.0"
}
}
required_version = ">= 0.14"
}# Example for Linux
PLUGIN_ARCH=linux_amd64
mkdir -p ~/.terraform.d/plugins/registry.example.com/telmate/proxmox/1.0.0/${PLUGIN_ARCH}
cp bin/terraform-provider-proxmox ~/.terraform.d/plugins/registry.example.com/telmate/proxmox/1.0.0/${PLUGIN_ARCH}/Use the proxmox_pool resource to create and manage VM or LXC pools within Proxmox. You can define a unique poolid and an optional comment for the pool.
resource "proxmox_pool" "example" {
poolid = "example-pool"
comment = "Example of a pool"
}To compile the provider executables manually, you must have Go installed.
git clone https://github.com/Telmate/terraform-provider-proxmox
cd terraform-provider-proxmoxmake:makeThe resulting executable will be located in the ./bin directory.
git clone https://github.com/Telmate/terraform-provider-proxmox
cd terraform-provider-proxmox
makeTo use an API token, set the PM_API_TOKEN_ID and PM_API_TOKEN_SECRET environment variables.
Note: When setting PM_API_TOKEN_ID in a shell, use single quotes because the token ID contains an exclamation mark (!).
# use single quotes for the API token ID because of the exclamation mark
export PM_API_TOKEN_ID='terraform-prov@pve!mytoken'
export PM_API_TOKEN_SECRET="afcd8f45-acc1-4d0f-bb12-a70b0777ec11"provider "proxmox" {
pm_api_url = "https://proxmox-server01.example.com:8006/api2/json"
}docs/guides/installation.md.