3 Guides containers
Forgejo Actions edited this page 2026-11-18 01:21:28 +00:00

Declaring Proxmox containers

The proxmox package declares LXC containers with the bpg/proxmox provider (0.122.0, pinned by hash). Existing containers are imported as they are; new ones are created from a template.

stack.RequireProvider(proxmox.Provider("https://192.168.1.209:8006/"))

c := proxmox.NewContainer(stack, "jellyfin", proxmox.ContainerProps{
	Node: "kratos", CTID: 101, Hostname: "jellyfin",
	Template: "local:vztmpl/debian-13-standard_13.1-2_amd64.tar.zst", OSType: "debian",
	Cores: 10, MemoryMiB: 8192, SwapMiB: 512, RootStorage: "px1", RootSizeGiB: 80,
	Features: proxmox.Features{Nesting: true, KeyCtl: true},
	Network: proxmox.Network{Bridge: "vmbr0", MAC: "bc:24:11:9a:2a:66",
		IPv4: "192.168.1.247/24", Gateway: "192.168.1.1", IPv6: "auto"},
	Mounts:      []proxmox.MountPoint{{Volume: "/vol1/media", Path: "/mnt/kratos/media"}},
	StartOnBoot: true, Running: true, Tags: []string{"community-script", "media"},
	Import: true, // adopt kratos/101
})

f.Add(fleet.Service{ID: "jellyfin", Container: c.Fleet(), Kind: fleet.CommunityScript, Script: "jellyfin"})

c.Fleet() returns the identity the deploy jobs check (node, CTID, hostname, IP), so a container is declared once. A DHCP interface (IPv4: "dhcp") must name its ReservedIP (the UniFi reservation in john/ops networking/).

What the construct owns

Written (drift shows in plans) Never reconciled
cores, memory, swap, root size (grow only), features, eth0 (bridge, MAC, IPv4/IPv6, firewall), DNS overrides, mount points, device passthrough, onboot, running state, tags template, privileged/unprivileged, root storage (fixed at creation); description (hand-written notes); the initial user account
  • Destroy is refused (prevent_destroy), and even a forced destroy is set to keep backups and detached disks.
  • Raw lxc.* lines are untouched (for example the NVIDIA passthrough on Jellyfin and Immich). The API cannot write them with a token.
  • Every attribute is decided. A test checks the construct against a schema snapshot of the pinned provider, nested blocks included. A provider bump fails until each new attribute is written or deliberately left out.

Credentials and trust

  • The provider reads the API token from PROXMOX_VE_API_TOKEN (user@realm!name=secret) and never from configuration. TLS is always verified (insecure = false): the node certificate is issued by the cluster's own CA, so that CA must be trusted where OpenTofu runs (SSL_CERT_FILE or the system store).
  • Creating a container with any feature flag other than nesting, or changing one later, needs root@pam on Proxmox; an API token gets HTTP 403. Imports and plans only need read access (VM.Audit, Datastore.Audit, Sys.Audit).
  • Proxmox ACL paths: containers are /vms/<ctid>, storages /storage/<id>, bridges /sdn/zones/localnetwork/<bridge>.

Restarts: the plan guard

Policy (the user's, 2026-11-18): new containers may restart freely; an existing running container may only be stopped, started, rebooted, replaced or deleted when it is explicitly approved for that deploy; the Proxmox host is never rebooted. (No container plan can reboot a host; host reboots are the user's last resort.)

bpg/proxmox 0.122.0 reboots a running container after an in-place update that changes memory, mount points, device passthrough, the network interface or IP config, DNS, hostname, entrypoint, environment, OS type, console, idmap or root disk mount options. Cores, CPU limit, tags, onboot, features and disk growth apply live. Deploy jobs must therefore run, between plan and apply:

tofu show -json tfplan | yawn plan-guard -allow 101,2026   # exit 3 = refused

yawn plan-guard prints every disruption and refuses (exit 3) if any is for a container not listed in -allow. Creates are always allowed. Apply only the saved plan that passed the guard.

Imports must plan with zero changes

Before applying an import, the plan must show 0 to add, 0 to change, 0 to destroy apart from the imports themselves. Declare every value exactly as pct config <ctid> reports it: tags sorted, MAC addresses in exactly the case Proxmox stores them (usually upper case; the provider compares case-sensitively and a network change would reboot the container), DHCP interfaces without gateways, and onboot absent read as false.