RR
← All work

2026 · Python Library

IaC Cost Estimator

Estimates the AWS bill of a Terraform or CDK plan before you deploy it, and gates CI when the cost delta is too high.

Role

Solo · design + build

Timeline

2026

Stack

Python, Terraform, AWS CDK, AWS Pricing API

Problem

Infrastructure changes are reviewed for correctness, but rarely for cost. The first time a team sees what a new instance family or region costs is on the monthly bill. Existing pre-deployment cost tools are written in Go and ship as CLIs, so Python teams can't import them as a library or embed them in their own tooling.

Approach

Parse the Terraform plan (or synthesized AWS CDK output), resolve the resource graph, and map each resource to its AWS Pricing API SKU for the right region and instance family. Every cloud provider sits behind a pluggable interface, so adding one doesn't touch the core.

example.py
from iac_cost import estimate, diff
 
before = estimate("plan-main.json", region="us-west-2")
after = estimate("plan-feature.json", region="us-west-2")
 
delta = diff(before, after)
delta.assert_under(monthly_usd=250)  # fails the CI job if exceeded

Architecture

architecture
  terraform plan ─┐
                  ├─► parser ──► resource graph ──► SKU resolver ──► AWS Pricing API
  cdk synth ──────┘                                     │
                                                        ▼
                                  provider plugins ──► estimate ──► diff ──► CI gate

Results

  • Importable as a plain Python library as well as a CLI, which the Go-based tools don't offer.
  • Diff mode shows the cost delta between two plan states, so a pull request can be gated on cost the same way it's gated on tests.

What I'd do next

Add usage-based estimates (data transfer, request counts) from historical CloudWatch metrics, and support GCP through the provider interface.