Terraform vs GitOps in the HomeLab

Invertedlight/ October 28, 2026/ DevOps, Home-Lab, Kubernetes

I used to think of Terraform and GitOps as two answers to the same question. They’re really two pipelines, and I run them in two places:

  • Skynet, my cluster at home, runs on hardware I already own. There is no Terraform there at all. It is GitOps only, with Flux.
  • My Azure course cluster starts from nothing. Terraform builds the cloud infrastructure the cluster runs on, then GitOps deploys onto it.

Skynet: GitOps only

Skynet’s machines already exist, so Terraform has nothing to build. Flux watches my homelab-cluster repo on GitHub, and everything inside the cluster is a file in that repo: the apps, the Grafana alert rules, the cloudflared connector, and the secrets, encrypted with SOPS before they’re committed. I change a file, commit, push, and Flux makes the cluster match. If I change something by hand, Flux puts it back on the next sync.

The way in never moves, either. My sites come in through a Cloudflare tunnel. The cloudflared pods connect out to Cloudflare, one wildcard DNS record points at the tunnel instead of an IP address, and the tunnel hands traffic to Traefik by its name inside the cluster. When Flux redeploys something, no DNS record changes.

Azure: Terraform, then GitOps

In Phase 7 of Mischa van den Burg’s Azure course, there is no cluster until Terraform makes one. Running terraform apply creates the Azure infrastructure: a resource group, the AKS cluster with two node pools of two VMs each, the cluster’s networking (Azure CNI with Cilium), Entra ID sign-in, a Key Vault, a storage account for database backups, and the Flux extension pointed at mercury-gitops, a GitOps repo dedicated to the Azure cluster. Then az aks get-credentials and kubelogin convert-kubeconfig -l azurecli got kubectl signed in through Entra ID, and Flux deployed Traefik, the CloudNativePG operator, Postgres and n8n from that repo. It is the same pipeline I use at home, just with its own repo, separate from homelab-cluster.

Side by side

Terraform pipeline (Azure)GitOps pipeline (Skynet and Azure, each with its own repo)
What it buildsAzure infrastructure: AKS and its node VMs, networking, Key Vault, the Flux extensionEverything inside the cluster: apps, alerts, ingress
How a change goes inEdit a .tf file, run plan, run applyEdit a YAML file, commit, push
Who runs itMe, from the terminalFlux, on its own sync
How it knows what existsIts state fileThe repo, compared against the live cluster
A change made by handShows up on the next planFlux puts it back on the next sync
SecretsWritten into Key VaultEncrypted in Git with SOPS on Skynet
Entry point and DNSNew public IP after each rebuild, DNS updated by handSkynet: fixed Cloudflare tunnel, no DNS changes on redeploy

The hand-off

In Azure, the pipelines meet at every rebuild. Running terraform destroy tears down those Azure resources, and terraform apply builds them again, so the cluster comes back brand new, with new values. Terraform prints two as outputs: the Key Vault name, which gets a random suffix, and the client ID of the Key Vault add-on. I copied those by hand into my GitOps files, keyvaultName in apps/base/customer1/secrets.yaml and userAssignedIdentityID in apps/staging/customer1/kustomization.yaml, pushed, and let Flux sync. Each rebuild also gave Traefik’s load balancer a new public IP, so I updated the Cloudflare DNS record by hand before the site worked again.

On Skynet, the tunnel is a fixed entry point, so none of that happens. In Azure, I’m the glue between the pipelines, and the copy-and-paste step is the easiest one to miss.

Here is my rule of thumb:

  • If it has to exist before the cluster, or lives outside it, Terraform builds it.
  • If it lives inside the cluster, it goes in Git for Flux.
  • Every value that crosses between them gets written down, because the hand-off is where things break.
Share this Post