This document describes the organization of the Terraform configuration files for the homelab infrastructure.
The Terraform configuration follows best practices with clear separation of concerns and logical grouping of resources.
These files contain fundamental Terraform configurations:
versions.tf- Terraform and provider version requirementsproviders.tf- Provider configurations (Kubernetes, Helm, Proxmox, etc.)variables.tf- Input variable declarationsoutputs.tf- Output value declarationsbackend.tf- Backend configuration (NFS-based state storage)main.tf- Entry point and documentation
Files managing physical and virtual infrastructure:
-
infrastructure-proxmox.tf- Proxmox VM definitions and cloud-init configurations- VM creation for control plane (bumblebee) and workers (prime, wheeljack)
- Cloud-init user data
- VM resource specifications
-
infrastructure-network.tf- Network infrastructure- MetalLB load balancer configuration
- NGINX Ingress Controller deployment
- Network policies and settings
Files managing core Kubernetes cluster and platform services:
-
kubernetes-cluster.tf- Kubernetes cluster bootstrapping- Kubeconfig management
- Control plane setup
- Worker node configuration
- Cluster API readiness checks
-
kubernetes-storage.tf- Storage configuration- NFS CSI driver deployment
- Storage class definitions
- PVC validation and checks
-
kubernetes-ingress.tf- Ingress resource definitions- Monitoring service ingresses (Grafana, Prometheus, Loki, Mimir)
- Application ingresses (Mylar, N8N)
Files managing monitoring, logging, and backup:
-
monitoring.tf- Observability stack- Prometheus deployment and configuration
- Grafana deployment and dashboards
- Loki log aggregation
- Mimir metrics storage
- Promtail log collection
- Node Exporter metrics
- Kube State Metrics
-
backup.tf- Backup infrastructure- ETCD backup CronJobs
- Data backup CronJobs
- Backup cleanup jobs
- Backup metrics collection
-
opnsense-logging.tf- OPNsense router log integration- Syslog-ng deployment
- Log forwarding to Loki
- Service configuration
Files managing user-facing applications:
-
applications-media.tf- Media applications- Mylar (comic book manager)
- Media namespace configuration
-
applications-automation.tf- Automation applications- N8N workflow automation
- Automation namespace configuration
- Use lowercase with hyphens
- Group by layer:
infrastructure-*,kubernetes-*,applications-* - Use descriptive names:
monitoring.tf,backup.tf
- Use underscores in resource names:
kubernetes_namespace.monitoring - Use descriptive, hierarchical names
- Prefix application resources with app name
Terraform automatically handles most dependencies, but the logical order is:
-
Infrastructure Layer - VMs and network
- Proxmox VMs created
- MetalLB installed
- Ingress controller deployed
-
Kubernetes Platform - Cluster setup
- Cluster bootstrapped
- Storage configured
- Kubeconfig available
-
Platform Services - Core services
- Monitoring stack deployed
- Backup jobs configured
- Logging integration enabled
-
Applications - User applications
- Media applications deployed
- Automation tools deployed
These resources control deployment flow:
null_resource.kubeconfig_ready- Gates all Kubernetes resourcesnull_resource.cluster_api_ready- Ensures API server is accessiblenull_resource.metallb_operational- Ensures load balancer is readynull_resource.validate_service_data- Validates NFS storage
The bootstrap_cluster variable controls cluster initialization:
true- Terraform manages full cluster lifecyclefalse- External cluster, Terraform manages resources only
All variables are defined in variables.tf and organized by category:
- Cluster Configuration - Control plane, workers, bootstrap settings
- Kubernetes Configuration - Version, network CIDRs
- SSH Configuration - Access credentials
- Network Configuration - MetalLB, Ingress IPs
- Ingress Hostnames - Service domain names
- Docker Hub Configuration - Image pull credentials
- Proxmox Configuration - API access, VM settings
- NFS Storage Configuration - Storage paths
- Backup Configuration - Retention, paths
All outputs are centralized in outputs.tf and grouped by:
- Infrastructure - VM info, cluster details, network config
- Storage - NFS and backup configuration
- Service Endpoints - URLs and access information
- Useful Commands - Common kubectl commands
- Separation of Concerns - Each file has a single, clear purpose
- Logical Grouping - Related resources grouped together
- Clear Naming - File and resource names are descriptive
- Documentation - Comments explain complex configurations
- Dependency Management - Explicit
depends_onwhere needed - Idempotency - Configurations can be safely re-applied
- Add to appropriate layer file (infrastructure-, kubernetes-, applications-*)
- Add required variables to
variables.tf - Add outputs to
outputs.tf - Update this documentation
- Locate the resource in its layer file
- Make changes following existing patterns
- Run
terraform validateto check syntax - Test with
terraform plan
- Create new file:
applications-[category].tf - Define namespace, deployment, service, ingress
- Add outputs to
outputs.tf - Update documentation
# Initialize Terraform
terraform init
# Validate configuration
terraform validate
# Plan changes
terraform plan
# Apply changes
terraform apply
# Target specific resource
terraform apply -target=resource.name
# Use helper scripts
./scripts/deployment/deploy-full-stack.sh