Project 09 · Infrastructure as code

Infrastructure-as-Code Data Platform

Every piece of this platform is code. Terraform creates the network, a Kubernetes cluster, object storage and a PostgreSQL database. Helm releases, also managed by Terraform, install an Apache Iceberg REST catalog backed by that database, Trino for SQL, the Spark operator for jobs, Airflow for scheduling, and Prometheus and Grafana for monitoring. The same modules build dev, staging and prod at different sizes, so a new environment is a pull request and about 18 minutes of terraform apply. Spark and Airflow run from Docker images pinned by digest.

  • Terraform
  • Docker
  • Kubernetes
  • Helm
  • Apache Iceberg
  • PostgreSQL
  • Grafana
Sample data Last 30 days · Sep 7 – Oct 6, 2026 Download data (CSV)

Resources by module and environment

Everything Terraform manages

Error budget used, 30 days

SLO 99.9% for each service

Cluster utilisation, prod

CPU and memory requested, hourly, last 7 days

Size of recent applies

Resources changed by the last 20 applies; red failed

Workloads, prod

State at 23:59 on Oct 6

Latest applies

From CI, newest first

Tables in the Iceberg REST catalog

Prod warehouse

How it works

Three layers, all in one repository: infrastructure, platform services and the images they run.

  1. 01 · Network & cluster

    Terraform: VPC + EKS

    Private subnets in three zones and an EKS cluster with on-demand nodes for services and spot nodes for Spark.

  2. 02 · Storage & state

    Terraform: S3 + RDS

    A versioned S3 warehouse bucket and PostgreSQL for the Iceberg catalog and Airflow's metadata.

  3. 03 · Platform services

    Helm, via Terraform

    Iceberg REST catalog, Trino, the Spark operator and Airflow, each a Helm release with values per environment.

  4. 04 · Images

    Docker

    Spark and Airflow images built in CI, scanned, and pinned by digest in the Helm values.

  5. 05 · Observe

    Prometheus + Grafana

    Cluster, service and SLO dashboards provisioned as code, with alerts on error-budget burn.

  6. 06 · Promote

    Pull requests

    Plans are reviewed on every PR; applies run from CI with remote state and locking.

  • One set of modules, three sizes. Environments differ only in a tfvars file: node counts, instance sizes, replicas and retention. Staging really is a smaller prod.
  • State is shared and locked. Remote state lives in S3 with a DynamoDB lock, one workspace per environment. Nobody applies from a laptop.
  • Rebuilding is rehearsed. Once a month CI destroys dev and recreates it from nothing, then runs smoke tests that query Iceberg through Trino. The last run took 18 minutes.
  • Drift is a bug. A nightly plan runs against every environment. Any difference opens an issue; this month two hand edits were found and moved into code.

Data model

The catalog's own state lives in PostgreSQL; environments differ only in their settings.

iceberg_tablesPostgreSQL · behind the Iceberg REST catalog
catalog_namevarchar
Catalog the table belongs to
table_namespacevarchar
For example analytics
table_namevarchar
For example orders
metadata_locationvarchar
Current metadata file in S3; a commit swaps it atomically
previous_metadata_locationvarchar
The one before, for safe concurrent commits
environments/*.tfvarsSettings that differ per environment
service_nodesnumber
dev 2 · staging 2 · prod 4
spark_max_nodesnumber
Spot node limit: dev 4 · staging 6 · prod 20
rds_instance_classstring
db.t4g.medium in dev and staging, db.r6g.large in prod
trino_workersnumber
dev 1 · staging 2 · prod 4
backup_retention_daysnumber
dev 1 · staging 7 · prod 30
terraform_appliesFrom CI logs · the CSV download
applied_attimestamp
When the apply finished
environmentstring
dev, staging or prod
pull_requeststring
PR that triggered it
added / changed / destroyedint
Resources in the plan
duration_s / resultint / string
How long it took and how it ended

Key code

The root Terraform module, the Helm releases for the lakehouse, and the Spark image.

Root module: network, cluster, storage, database and the platform services, all parameterised by environment.

terraform {
  required_version = ">= 1.8"
  required_providers {
    aws  = { source = "hashicorp/aws", version = "~> 5.60" }
    helm = { source = "hashicorp/helm", version = "~> 2.15" }
  }
  backend "s3" {
    bucket         = "dataplatform-tf-state"
    key            = "platform/terraform.tfstate"   # one workspace per environment
    region         = "us-east-1"
    dynamodb_table = "dataplatform-tf-locks"
    encrypt        = true
  }
}

locals {
  name = "dp-${terraform.workspace}"
}

module "network" {
  source     = "./modules/network"
  name       = local.name
  cidr_block = var.vpc_cidr
  azs        = ["us-east-1a", "us-east-1b", "us-east-1c"]
}

module "eks" {
  source          = "terraform-aws-modules/eks/aws"
  version         = "~> 20.24"
  cluster_name    = local.name
  cluster_version = "1.31"
  vpc_id          = module.network.vpc_id
  subnet_ids      = module.network.private_subnet_ids

  eks_managed_node_groups = {
    services = {
      instance_types = [var.service_instance_type]
      min_size       = var.service_nodes
      max_size       = var.service_nodes + 2
      desired_size   = var.service_nodes
    }
    spark = {
      capacity_type  = "SPOT"
      instance_types = ["r6i.2xlarge", "r6a.2xlarge", "r5.2xlarge"]
      min_size       = 0
      max_size       = var.spark_max_nodes
      desired_size   = 0
      labels         = { workload = "spark" }
      taints = {
        spark = { key = "workload", value = "spark", effect = "NO_SCHEDULE" }
      }
    }
  }
}

module "warehouse" {
  source      = "./modules/storage"
  bucket_name = "${local.name}-warehouse"
  versioning  = true
}

module "catalog_db" {
  source                = "./modules/postgres"
  identifier            = "${local.name}-catalog"
  instance_class        = var.rds_instance_class
  subnet_ids            = module.network.private_subnet_ids
  allowed_sg_ids        = [module.eks.node_security_group_id]
  backup_retention_days = var.backup_retention_days
}

module "platform" {
  source        = "./modules/platform"   # Helm releases, see helm.tf
  environment   = terraform.workspace
  warehouse_uri = "s3://${module.warehouse.bucket_name}/warehouse"
  catalog_db    = module.catalog_db.connection
  trino_workers = var.trino_workers
  image_digests = var.image_digests
}

Engineering notes

A rebuild drill every month

On Sep 28 CI destroyed dev and recreated it from nothing in 18 minutes. Smoke tests then created an Iceberg table, wrote to it with Spark and read it back through Trino.

The one failed apply

PR #296 failed in staging when AWS refused more spot vCPUs. Terraform had recorded what it already created, so after the quota was raised the re-run only added the rest.

Airflow is spending its budget

The Airflow scheduler restarted four times after hitting its memory limit, using about 78% of its monthly error budget. The limit is raised in the next PR.

Spot for Spark, on-demand for services

Spark runs on spot nodes behind a taint, so catalog and query services never land there. Nightly jobs cost about 65% less than on on-demand nodes.

About the data. Every number on this page is sample data from a seeded generator written for this project. It is shaped to behave like a real workload, with daily peaks, late events and the odd incident, but it does not come from any employer or client. Download it as terraform_applies.csv or read data.json.