We added carbon linting to Terraform PRs — here's how it works
Most carbon tracking tools are dashboards built for sustainability officers.
They pull three-month-old billing data and produce a PDF. Engineers never see it.
This post is about shifting that left — into the pull request, before
infrastructure is provisioned.
The problem with post-hoc measurement
By the time AWS's Carbon Footprint Tool tells you that your us-east-1
cluster emits twice as much as us-west-2 would have, it has been running
for a quarter. The architecture is locked in, the carbon is burnt.
The only intervention point that changes what gets deployed is the PR.
What GreenOps CLI does
It's a GitHub Action that reads a terraform show -json plan output and
posts a carbon and cost diff directly on the PR.
Here's what a developer sees:
🌿 GreenOps Carbon Analysis
This plan adds +12.94 kg CO2e/month (~$210.24/mo)
💡 2 recommendations found — potential saving: −4.71kg CO2e/month | −$41.61/month
Resource | Instance | Region | CO2e/mo | Cost/mo | Action
aws_instance.api | m5.xlarge | us-east-1 | 8.63kg | $140.16 | → Switch to m6g.xlarge
aws_db_instance.main | m5.large | us-east-1 | 4.31kg | $70.08 | → Switch to m6g.large
Math is MIT-licensed and auditable.
No AWS credentials required. No outbound network calls from the CLI.
The emission factors are a static JSON file you can read in ten minutes.
How the math works
The emission calculation is a linear interpolation model:
W = W_idle + (W_max - W_idle) × utilisation
energy_kwh = W × PUE × hours / 1000
co2e_g = energy_kwh × grid_intensity_gco2e_per_kwh
For m5.large in us-east-1 at 50% utilisation this produces
4,313.57g CO2e/month. That value is asserted in engine.test.ts.
You can verify it yourself from factors.json in under five minutes.
The full methodology — every formula, every assumption, every data source —
is in METHODOLOGY.md and MIT-licensed.
Adding it to your workflow
- name: Generate Terraform Plan
run: |
terraform init
terraform plan -out=tfplan
terraform show -json tfplan > plan.json
- name: GreenOps Carbon Lint
uses: omrdev1/greenops-cli@v0
with:
plan-file: plan.json
github-token: ${{ secrets.GITHUB_TOKEN }}
The Action requires only pull-requests: write. Nothing broader.
Current limitations
- AWS only. No Azure, no GCP.
- EC2 and RDS only. No Lambda, no ECS.
- No embodied carbon.
- Provider alias regions are not resolved — affected resources are
skipped with a
known_after_applyreason.
All of the above are tracked in open issues.
Why open source the methodology
Every other tool in this space uses proprietary emission factors.
That doesn't survive a CSRD audit where a compliance officer needs
to trace exactly how a number was produced.
If you disagree with an assumption, open a PR and change it.
Top comments (0)