202501202243 Homelab Portability with IaC
In the 202412271311 Homelab Redesign 2025, I delved briefly into how the physical infrastructure could be improved. At the same time, I extended that further in 202501111134 A Portable Homelab which seeks to create an idempotent deployment of machines through Ansible 202501180024 Achieving Portability with Ansible
To take that one step further, Ansible can be coupled with Terraform as a way to handle the creation of stateful systems through the concept of Providers. At it’s core, Ansible is used to automate, agentless, the necessary binaries to bootstrap a machine as to how I intend it to be.
Terraform on the other hand, allows me to provision VM’s and/or LXC’s in a way that can determine how the infrastructure of my homelab could be, dictated through a pattern called IaC. In short, IaC (Infrastructure-as-code) provides the ability to provision resources, within an environment (my homelab) through declarative commands – code. In contrast, clicking through a UI to provision a resource has one big downside – the lack of traceability as to what is happening.
As much as my homelab is intended to be portable, the goal of portability is to also achieve minimal downtime. Looking at the Homelab Topology, I drew out a plan to locate databases outside of the cluster. A database that is dead is as useful as a Hello World application. Stateful systems should be loosely coupled – placing a database outside ensures that the cluster can operate without being tightly coupled to the domains of storage (either block, blob. Whatever you want to call it). I outlined it in the 202412271311 Homelab Redesign 2025#^bf6275 where I talked about moving the file storage into a separate physical entity.
Fundamentally, putting it into terraform negates any manual instructions. The code becomes self-documenting.
Confusing? I know. Here’s how I intend to use Terraform, alongside Ansible when provisioning VMs or LXCs
- Proxmox (or any hypervisor) will be operated through the Terraform provider (plugin) for the provisioning of virtual machines and any resource configurations (CPU, RAM etc).
- Although I use Proxmox here, it can be any cloud provider. Proxmox is my way of treating a computer as a cloud service provider.
- Bootstrapping the configured resource with the necessary binaries, such as hardening can be done through Ansible. Here are some examples:
- Installing of a Tailscale onto the provisioned resource
- Hardening the SSH keys