How obmotum/tofu-proxmox-iac works
Purpose and Entry Points
This repository is an OpenTofu-based homelab provisioning system for Debian VMs and Docker hosts on Proxmox VE. The operational entry point is tofu apply from the root module, with environment authentication supplied through VAULT_TOKEN. Root orchestration lives in main.tf; deployment-specific inputs are declared in variables.tf and supplied locally from terraform.tfvars (seeded by terraform.tfvars.example).
Root Orchestration and Secrets Boundary
The root module configures providers, retrieves Proxmox credentials and SSH material from HashiCorp Vault, and declares VM instances. Vault is the credential boundary: API tokens, passwords, and public keys are sourced dynamically rather than committed. Ephemeral OpenTofu resources are intended to prevent sensitive password values entering state.
Paths: main.tf, variables.tf, terraform.tfvars.example.
Reusable Debian VM Module
modules/debian_vm is the architecture’s compute abstraction. It accepts machine sizing, networking, identity, and workload-role inputs, then creates a Proxmox VM from a Debian cloud image. The install_docker input controls both VM resource/profile behavior and the host’s downstream Ansible grouping.
Paths: modules/debian_vm/main.tf, modules/debian_vm/variables.tf, modules/debian_vm/versions.tf.
Proxmox and Cloud-Init Bootstrap
OpenTofu uses the bpg/proxmox provider to download/cache Debian cloud images, clone/configure VMs, and attach generated Cloud-Init snippets. Cloud-Init establishes hostname and networking, injects SSH access, enables passwordless sudo, and installs/starts the QEMU guest agent. The guest agent is the readiness boundary between infrastructure creation and post-boot configuration.
Paths: main.tf, modules/debian_vm/main.tf.
Configuration-Management Handover
Once guest readiness is detected, module-level local-exec logic generates an Ansible inventory dynamically from provisioned VM/module attributes and invokes Ansible. This creates a deliberate boundary: OpenTofu owns infrastructure and bootstrap; Ansible owns package and role configuration. The execution environment must have OpenTofu and Ansible available.
Paths: modules/debian_vm/main.tf, install_packages.yml.
Ansible Workload Configuration
The shared playbook targets generated inventory groups, waits for Cloud-Init/apt activity to release package-manager locks, installs baseline packages, and conditionally configures Docker hosts. Its OS-agnostic design makes it the post-provisioning policy layer rather than embedding software configuration in VM resources.
Paths: install_packages.yml, modules/debian_vm/main.tf.
State and Runtime Infrastructure
OpenTofu uses a local backend, with state expected to reside on an NFS share bind-mounted into an unprivileged LXC runtime. External dependencies are Proxmox VE, HashiCorp Vault, Debian image sources, NFS-backed state storage, and SSH reachability from the OpenTofu/Ansible runner to created VMs.
Paths: main.tf, .gitignore, README.md.
Main entry points: debian_vm/main.tf Debian VM module · main.tf Root orchestration · variables.tf Deployment inputs · install_packages.yml Package configuration playbook
Components 17
OpenTofu root
- Tofu/Ansible runner · Runs tofu apply and must reach VMs over SSH.
- Root orchestration · Configures providers, secrets retrieval, and VM declarations.
main.tf - Deployment inputs · Local environment-specific sizing and deployment values.
variables.tf - Input template
terraform.tfvars.example
VM provisioning
- Debian VM module · Applies sizing, networking, identity, and workload-role inputs.
modules/debian_vm/main.tf - VM module interface · Includes install_docker, which affects VM profile and Ansible grouping.
modules/debian_vm/variables.tf - Provider requirements · Declares module provider requirements including bpg/proxmox.
modules/debian_vm/versions.tf - Cloud-Init bootstrap · Sets hostname and networking, SSH access, sudo, and the QEMU guest agent.
modules/debian_vm/main.tf - Provisioned Debian VMs
modules/debian_vm/main.tf - Guest readiness · Signals post-boot readiness before configuration management begins.
modules/debian_vm/main.tf
Configuration handover
- Inventory and Ansible handover · Generates inventory from VM attributes and invokes Ansible.
modules/debian_vm/main.tf - Package configuration playbook · Waits for package locks, installs baseline packages, and configures Docker hosts conditionally.
install_packages.yml - Configured workload hosts
External infrastructure
- HashiCorp Vault · Supplies Proxmox credentials and SSH material through VAULT_TOKEN authentication.
- NFS-backed local state · Local backend state is expected on an NFS share mounted into the runtime.
- Proxmox VE
- Debian image sources
Connections 18
- Tofu/Ansible runner → Root orchestration: tofu apply
- Input template → Deployment inputs: seeds
- Deployment inputs → Root orchestration: supplies values
- Root orchestration → HashiCorp Vault: reads credentials and SSH material
- Root orchestration → NFS-backed local state: stores state
- Root orchestration → Debian VM module: declares VM instances
- VM module interface → Debian VM module: configures
- Provider requirements → Debian VM module: constrains provider
- Debian VM module → Debian image sources: downloads and caches image
- Debian VM module → Cloud-Init bootstrap: generates
- Debian VM module → Proxmox VE: creates and configures VMs
- Cloud-Init bootstrap → Provisioned Debian VMs: bootstraps
- Proxmox VE → Provisioned Debian VMs: hosts
- Provisioned Debian VMs → Guest readiness: reports ready
- Guest readiness → Inventory and Ansible handover: unblocks
- Inventory and Ansible handover → Package configuration playbook: generates inventory and invokes
- Package configuration playbook → Configured workload hosts: applies baseline and Docker policy
- Tofu/Ansible runner → Configured workload hosts: SSH reachability