# obmotum/tofu-proxmox-iac architecture

> Architecture diagram of the GitHub repository obmotum/tofu-proxmox-iac, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/obmotum/tofu-proxmox-iac
- Repository: https://github.com/obmotum/tofu-proxmox-iac

## Overview

#### 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: [`modules/debian_vm/main.tf`](https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/main.tf) (Debian VM module), [`main.tf`](https://github.com/obmotum/tofu-proxmox-iac/blob/main/main.tf) (Root orchestration), [`variables.tf`](https://github.com/obmotum/tofu-proxmox-iac/blob/main/variables.tf) (Deployment inputs), [`install_packages.yml`](https://github.com/obmotum/tofu-proxmox-iac/blob/main/install_packages.yml) (Package configuration playbook)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_root["OpenTofu root"]
  node_runner{{"Tofu/Ansible runner<br/>execution environment"}}
  node_root_main["Root orchestration<br/>OpenTofu root module<br/>[main.tf]"]
  node_inputs["Deployment inputs<br/>variables and tfvars<br/>[variables.tf]"]
  node_tfvars_example["Input template<br/>tfvars example"]
end

subgraph group_compute["VM provisioning"]
  node_vm_module["Debian VM module<br/>reusable compute module<br/>[main.tf]"]
  node_module_inputs["VM module interface<br/>module variables<br/>[variables.tf]"]
  node_provider_lock["Provider requirements<br/>module versions<br/>[versions.tf]"]
  node_cloud_init["Cloud-Init bootstrap<br/>generated VM snippet<br/>[main.tf]"]
  node_vm["Provisioned Debian VMs<br/>Proxmox virtual machines<br/>[main.tf]"]
  node_guest_agent(("Guest readiness<br/>QEMU guest agent boundary<br/>[main.tf]"))
end

subgraph group_config["Configuration handover"]
  node_inventory_handover["Inventory and Ansible handover<br/>local-exec workflow<br/>[main.tf]"]
  node_playbook["Package configuration playbook<br/>Ansible playbook"]
  node_configured_hosts["Configured workload hosts<br/>Debian and Docker hosts"]
end

subgraph group_external["External infrastructure"]
  node_vault[("HashiCorp Vault<br/>secrets service")]
  node_state[("NFS-backed local state<br/>OpenTofu backend")]
  node_proxmox{{"Proxmox VE<br/>virtualization platform"}}
  node_debian_images[("Debian image sources<br/>cloud image source")]
end

node_runner -->|"tofu apply"| node_root_main
node_tfvars_example -.->|"seeds"| node_inputs
node_inputs -->|"supplies values"| node_root_main
node_root_main -->|"reads credentials and SSH material"| node_vault
node_root_main -->|"stores state"| node_state
node_root_main -->|"declares VM instances"| node_vm_module
node_module_inputs -->|"configures"| node_vm_module
node_provider_lock -.->|"constrains provider"| node_vm_module
node_vm_module -->|"downloads and caches image"| node_debian_images
node_vm_module -->|"generates"| node_cloud_init
node_vm_module -->|"creates and configures VMs"| node_proxmox
node_cloud_init -->|"bootstraps"| node_vm
node_proxmox -->|"hosts"| node_vm
node_vm -->|"reports ready"| node_guest_agent
node_guest_agent -->|"unblocks"| node_inventory_handover
node_inventory_handover -->|"generates inventory and invokes"| node_playbook
node_playbook -->|"applies baseline and Docker policy"| node_configured_hosts
node_runner -.->|"SSH reachability"| node_configured_hosts

click node_root_main "https://github.com/obmotum/tofu-proxmox-iac/blob/main/main.tf"
click node_inputs "https://github.com/obmotum/tofu-proxmox-iac/blob/main/variables.tf"
click node_tfvars_example "https://github.com/obmotum/tofu-proxmox-iac/blob/main/terraform.tfvars.example"
click node_vm_module "https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/main.tf"
click node_module_inputs "https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/variables.tf"
click node_provider_lock "https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/versions.tf"
click node_cloud_init "https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/main.tf"
click node_vm "https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/main.tf"
click node_guest_agent "https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/main.tf"
click node_inventory_handover "https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/main.tf"
click node_playbook "https://github.com/obmotum/tofu-proxmox-iac/blob/main/install_packages.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_runner,node_root_main,node_inputs,node_tfvars_example toneBlue
class node_vm_module,node_module_inputs,node_provider_lock,node_cloud_init,node_vm,node_guest_agent toneAmber
class node_inventory_handover,node_playbook,node_configured_hosts toneMint
class node_vault,node_state,node_proxmox,node_debian_images toneRose
```

## Components

### OpenTofu root

- **Tofu/Ansible runner**: execution environment · Runs tofu apply and must reach VMs over SSH.
- [Root orchestration](https://github.com/obmotum/tofu-proxmox-iac/blob/main/main.tf): OpenTofu root module · Configures providers, secrets retrieval, and VM declarations. · `main.tf`
- [Deployment inputs](https://github.com/obmotum/tofu-proxmox-iac/blob/main/variables.tf): variables and tfvars · Local environment-specific sizing and deployment values. · `variables.tf`
- [Input template](https://github.com/obmotum/tofu-proxmox-iac/blob/main/terraform.tfvars.example): tfvars example · `terraform.tfvars.example`

### VM provisioning

- [Debian VM module](https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/main.tf): reusable compute module · Applies sizing, networking, identity, and workload-role inputs. · `modules/debian_vm/main.tf`
- [VM module interface](https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/variables.tf): module variables · Includes install_docker, which affects VM profile and Ansible grouping. · `modules/debian_vm/variables.tf`
- [Provider requirements](https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/versions.tf): module versions · Declares module provider requirements including bpg/proxmox. · `modules/debian_vm/versions.tf`
- [Cloud-Init bootstrap](https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/main.tf): generated VM snippet · Sets hostname and networking, SSH access, sudo, and the QEMU guest agent. · `modules/debian_vm/main.tf`
- [Provisioned Debian VMs](https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/main.tf): Proxmox virtual machines · `modules/debian_vm/main.tf`
- [Guest readiness](https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/main.tf): QEMU guest agent boundary · Signals post-boot readiness before configuration management begins. · `modules/debian_vm/main.tf`

### Configuration handover

- [Inventory and Ansible handover](https://github.com/obmotum/tofu-proxmox-iac/blob/main/modules/debian_vm/main.tf): local-exec workflow · Generates inventory from VM attributes and invokes Ansible. · `modules/debian_vm/main.tf`
- [Package configuration playbook](https://github.com/obmotum/tofu-proxmox-iac/blob/main/install_packages.yml): Ansible playbook · Waits for package locks, installs baseline packages, and configures Docker hosts conditionally. · `install_packages.yml`
- **Configured workload hosts**: Debian and Docker hosts

### External infrastructure

- **HashiCorp Vault**: secrets service · Supplies Proxmox credentials and SSH material through VAULT_TOKEN authentication.
- **NFS-backed local state**: OpenTofu backend · Local backend state is expected on an NFS share mounted into the runtime.
- **Proxmox VE**: virtualization platform
- **Debian image sources**: cloud image source

## Connections

- 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
