Terraform Infrastructure-as-Code

Relevant source files

This section covers the Terraform configurations used to provision external and internal infrastructure components beyond the Proxmox hypervisor. It details the management of Cloudflare DNS and networking, S3 object storage through Garage and Backblaze, and the complex identity provider setup for Authentik.

State Management and Backend

The repository utilizes Cloudflare R2 as the primary S3-compatible backend for Terraform state files. This pattern ensures that infrastructure state is stored off-site, enabling recovery even if the local Proxmox cluster or Garage S3 storage is unavailable.

R2 Backend Pattern

The backend is configured using the s3 block with custom endpoints pointing to Cloudflare’s R2 storage infrastructure/terraform/authentik/main.tf12-27 Key features include:

Sources:infrastructure/terraform/authentik/main.tf12-27infrastructure/terraform/cloudflare/providers.tf15-31


Cloudflare DNS and Networking

The Cloudflare Terraform module manages public DNS records, mail configuration, and external ingress routing for services running outside the primary cluster or requiring public visibility.

DNS Record Architecture

Records are defined in a cloudflare_record local map infrastructure/terraform/cloudflare/locals.tf19-166

Code-to-Cloud Mapping

The following diagram shows how Terraform local variables map to Cloudflare Provider resources.

Diagram: Cloudflare Resource Mapping

[Flowchart Diagram]

Sources:infrastructure/terraform/cloudflare/locals.tf19-180infrastructure/terraform/cloudflare/providers.tf33-36


Authentik Identity Provider

The Authentik configuration is the most complex Terraform module, managing the entire OIDC/SAML and Proxy lifecycle for the home-ops environment.

Application Provisioning

Authentik applications are categorized into two types:

  1. Proxy Applications: Managed via a local module proxy_applicationinfrastructure/terraform/authentik/applications.tf75-91 These provide authentication headers to legacy applications or those without native OIDC support (e.g., echo-server, prometheus-ext) infrastructure/terraform/authentik/applications.tf12-72
  2. OAuth2/OIDC Applications: Defined in a local map applicationsinfrastructure/terraform/authentik/applications.tf106-170 This includes grafana, headlamp, jellyfin, and forgejo.

Authentication Pipeline

The module configures the full Authentik “Flow” and “Stage” architecture:

Diagram: Authentik Authentication Flow Logic

[Flowchart Diagram]

Sources:infrastructure/terraform/authentik/stages.tf25-68infrastructure/terraform/authentik/flows.tf38-63


S3 Bucket Provisioning (Garage)

The s3/garage module manages object storage buckets within the local cluster’s Garage S3 deployment.

Module: garage

This submodule encapsulates the creation of a bucket, an access key, and the association between them.

Configuration Parameters

VariableDescriptionDefault
bucket_nameName of the S3 bucket and alias(Required)
admin_userID of the admin key to grant access(Required)
website_access_enabledEnables static site hostingfalse

Sources:infrastructure/terraform/s3/garage/modules/garage/main.tf1-43infrastructure/terraform/s3/garage/modules/garage/variables.tf1-33