Resources by module and environment
Everything Terraform manages
Project 09 · Infrastructure as code
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.
Everything Terraform manages
SLO 99.9% for each service
CPU and memory requested, hourly, last 7 days
Resources changed by the last 20 applies; red failed
State at 23:59 on Oct 6
From CI, newest first
Prod warehouse
Three layers, all in one repository: infrastructure, platform services and the images they run.
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.
02 · Storage & state
Terraform: S3 + RDS
A versioned S3 warehouse bucket and PostgreSQL for the Iceberg catalog and Airflow's metadata.
03 · Platform services
Helm, via Terraform
Iceberg REST catalog, Trino, the Spark operator and Airflow, each a Helm release with values per environment.
04 · Images
Docker
Spark and Airflow images built in CI, scanned, and pinned by digest in the Helm values.
05 · Observe
Prometheus + Grafana
Cluster, service and SLO dashboards provisioned as code, with alerts on error-budget burn.
06 · Promote
Pull requests
Plans are reviewed on every PR; applies run from CI with remote state and locking.
The catalog's own state lives in PostgreSQL; environments differ only in their settings.
iceberg_tablesPostgreSQL · behind the Iceberg REST catalogcatalog_namevarchartable_namespacevarcharanalyticstable_namevarcharordersmetadata_locationvarcharprevious_metadata_locationvarcharenvironments/*.tfvarsSettings that differ per environmentservice_nodesnumberspark_max_nodesnumberrds_instance_classstringdb.t4g.medium in dev and staging, db.r6g.large in prodtrino_workersnumberbackup_retention_daysnumberterraform_appliesFrom CI logs · the CSV downloadapplied_attimestampenvironmentstringdev, staging or prodpull_requeststringadded / changed / destroyedintduration_s / resultint / stringThe 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
}
The lakehouse services as Helm releases. Trino depends on the catalog, so it is installed after it.
resource "helm_release" "iceberg_rest" {
name = "iceberg-rest"
namespace = "lakehouse"
create_namespace = true
repository = "oci://registry.example.com/charts"
chart = "iceberg-rest-catalog"
version = "0.4.2"
values = [templatefile("${path.module}/values/iceberg-rest.yaml", {
warehouse = var.warehouse_uri
jdbc_url = "jdbc:postgresql://${var.catalog_db.host}:5432/${var.catalog_db.database}"
image = "registry.example.com/iceberg-rest@${var.image_digests.iceberg_rest}"
})]
set_sensitive {
name = "catalog.jdbc.password"
value = var.catalog_db.password
}
}
resource "helm_release" "trino" {
name = "trino"
namespace = "lakehouse"
repository = "https://trinodb.github.io/charts"
chart = "trino"
version = "0.30.0"
values = [templatefile("${path.module}/values/trino.yaml", {
workers = var.trino_workers
iceberg_rest_uri = "http://iceberg-rest.lakehouse.svc:8181"
warehouse = var.warehouse_uri
})]
depends_on = [helm_release.iceberg_rest]
}
resource "helm_release" "spark_operator" {
name = "spark-operator"
namespace = "spark"
create_namespace = true
repository = "https://kubeflow.github.io/spark-operator"
chart = "spark-operator"
version = "2.0.2"
set {
name = "spark.jobNamespaces[0]"
value = "spark"
}
}
The Spark image used by every job: Spark 3.5 plus the Iceberg runtime and AWS bundle, pinned versions only.
# Spark 3.5 with Iceberg and S3 support, for jobs run by the Spark operator
FROM apache/spark:3.5.3-scala2.12-java17-python3-ubuntu
ARG ICEBERG_VERSION=1.6.1
ARG MAVEN=https://repo1.maven.org/maven2/org/apache/iceberg
USER root
ADD --chmod=644 ${MAVEN}/iceberg-spark-runtime-3.5_2.12/${ICEBERG_VERSION}/iceberg-spark-runtime-3.5_2.12-${ICEBERG_VERSION}.jar /opt/spark/jars/
ADD --chmod=644 ${MAVEN}/iceberg-aws-bundle/${ICEBERG_VERSION}/iceberg-aws-bundle-${ICEBERG_VERSION}.jar /opt/spark/jars/
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt && rm /tmp/requirements.txt
COPY jobs/ /opt/spark/work-dir/jobs/
USER spark
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.
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.
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.
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.