# Per-app LXC modules are called from here, so there is one place that knows # what infrastructure exists. Each module lives with its app in # src//terraform/ and outputs the guest's address, which the Ansible # side then picks up from the Proxmox API (inventory/proxmox.yml) rather than # by wiring outputs into inventory by hand. # The shared Postgres, and the first module here that is infrastructure other # modules depend on rather than an app in its own right. Declared first for # readability only — Terraform orders by dependency, not by position, and # nothing else in this file references it. The ordering that does matter is # on the Ansible side, where a guest's `db:` provisioning needs this cluster # already answering; see the runbook in docs/postgres-proxmox.md. module "postgres" { source = "../../../src/shared/postgres/terraform" node_name = var.proxmox_node template_file_id = var.lxc_template_file_id ssh_public_keys = var.ssh_public_keys hostname = "postgres" vm_id = 161 ip_address = "192.168.50.54/24" gateway = "192.168.50.254" cores = 2 memory = 2048 # Sized for every database this host will ever hold, not for the OS. The # one-volume rule below means growth happens here rather than by adding a # second disk: `terraform apply` turns an increase into a `pct resize` of # the rootfs, which on ZFS is a refquota change — online, no data move, no # filesystem grow step. It is one-way, though; shrinking is a replacement # and `prevent_destroy` blocks it, so overshoot rather than creep upward. disk_size = 256 # The ZFS pool, so the guest's volume can be replicated at all, and the # second node to replicate it to. Both are the whole point of this module # differing from the one below — see src/shared/postgres/terraform/main.tf. datastore_id = "AppData" replication_target_node = var.proxmox_replication_node } module "forgejo" { source = "../../../src/forgejo/terraform" # The second node, not `var.proxmox_node` — a deliberate split of the two # guests across the cluster rather than an oversight. Written as a literal # here for the same reason `hostname`/`vm_id`/`ip_address` are: it states # where this one guest goes. `var.proxmox_replication_node` happens to hold # the same string today, but it means "where Postgres replicates to", and # borrowing it would tie Forgejo's placement to a decision about the # database. # # Safe to change only while this container does not exist. Once it does, the # provider treats `node_name` as a replacement — and `prevent_destroy` in # the module turns that into a failed plan, which is the intended outcome: # moving a live Forgejo between nodes is a Proxmox migration, not a # `terraform apply`. node_name = "turtle-proxmox-02" template_file_id = var.lxc_template_file_id ssh_public_keys = var.ssh_public_keys hostname = "forgejo" vm_id = 160 ip_address = "192.168.50.52/24" gateway = "192.168.50.254" cores = 2 memory = 2048 # Overrides the module default only in the sense of restating it; both are # 256 GiB. Growing this is one-way, same as the Postgres guest above: # `terraform apply` turns an increase into an online `pct resize` of the # rootfs, but shrinking is a replacement and `prevent_destroy` blocks it. # Sized generously because *everything* Forgejo owns is on this volume — # repos, LFS, attachments, indexers, and the local database dumps. disk_size = 256 # The ZFS pool, which exists on both nodes, rather than the module's # `local-lvm` default — this cluster has no storage by that name. No # replication job to go with it, unlike the Postgres guest above: Forgejo's # off-box copy is the vzdump archive `pve_backup` writes to the NAS, which # is a complete filesystem restore point precisely because nothing here is # bind-mounted. datastore_id = "AppData" } # Consumed by the Proxmox nodes' host_vars, which can pin the vzdump job to # explicit VMIDs. Kept as an output rather than restated there so the two # can't drift. output "backup_vmids" { description = "VMIDs of the guests this configuration creates, for the vzdump job." value = [module.postgres.vm_id, module.forgejo.vm_id] } # The address every app's `db.provision_host` and `DB_HOST` has to agree with. # An output rather than something to look up in the Proxmox UI, because it is # copied into several files by hand and this is the one authoritative copy. output "postgres_address" { description = "LAN address of the shared Postgres LXC." value = module.postgres.ip_address }