Terraform plan JSON cost estimation: the most accurate input
Estimating from terraform show -json prices the resolved resources — variables, conditionals, data sources all computed — unlike parsing raw HCL. Here's how to generate it, why it's accurate, and how it fits CI.
Quick answer
Estimating from a Terraform plan (terraform show -json) is the most accurate approach because every value is resolved — variables, conditionals, data sources, module outputs. Generate it with terraform plan -out then show -json, and feed it to the estimator. No apply needed, and it's the ideal CI input since your pipeline already runs plan.
There are two ways to estimate Terraform cost: parse the .tf files directly, or estimate from a plan. Both have their place, but for anything beyond a static configuration, the plan wins on accuracy — because it's the only one that knows what your config actually resolves to.
Why the plan is more accurate
Raw HCL is full of unresolved expressions: a count driven by a variable, an instance type chosen by a conditional, a size pulled from a data source. A parser reading the files can't know the final values without evaluating them. terraform plan evaluates everything — it has to, to show you the diff — so the plan JSON contains the resolved resource set that will actually be created.
Generating the plan JSON
# 1. Save the plan
terraform plan -out=tfplan
# 2. Convert to JSON
terraform show -json tfplan > plan.json
# 3. Estimate from it
c3x estimate --plan plan.jsonNone of this provisions anything — plan only computes the diff. You get fully-resolved resources for pricing without touching real infrastructure, the foundation of pre-deployment estimation.
It fits CI naturally
Your pipeline already runs terraform plan. Add the -out and show -json steps, then feed the JSON to the cost estimate — you get maximum accuracy from a plan the pipeline was generating anyway. This is the input behind the GitLab CI and budget-guardrail workflows.
When raw HCL is fine
For a static configuration with literal values, parsing the .tf files gives the same answer without needing state access or a plan — handy for a quick local estimate or a pre-commit hook. Reach for the plan when the configuration is dynamic.
FAQ
Why estimate cost from a Terraform plan instead of the .tf files?
A plan has resolved values — interpolations, variables, data sources, and module outputs are all computed — so the estimate reflects what will actually be created. Parsing raw .tf files means many attributes are still unknown expressions, which forces guesses. The plan JSON is the most accurate input for cost estimation.
How do I generate Terraform plan JSON?
Run `terraform plan -out=tfplan` to save the plan, then `terraform show -json tfplan > plan.json` to convert it to machine-readable JSON. That file contains the fully-resolved resource changes, which a cost estimator reads to price the planned infrastructure.
Does estimating from a plan require an apply?
No. `terraform plan` computes what would change without provisioning anything — it just needs to refresh state and resolve values. You get the resolved resource set for pricing without creating a single resource, which is exactly the point of pre-deployment estimation.
Is plan-based estimation more accurate than parsing HCL?
Yes, materially. Counts driven by variables, instance types chosen by conditionals, sizes from data sources — all resolve in the plan but are opaque in raw HCL. For dynamic configurations, the plan is the only way to price what will really exist.
Can I use plan JSON in CI?
Yes — it's the recommended CI flow. Your pipeline already runs `terraform plan`; add the `-out` and `show -json` steps, then feed the JSON to the cost estimator. You get the most accurate estimate using a plan the pipeline was producing anyway.
Does C3X support Terraform plan JSON?
Yes. C3X reads `terraform show -json` output with `c3x estimate --plan plan.json`, pricing the resolved resources against a live catalog. It also parses raw HCL when a plan isn't available, but the plan gives the most accurate result.
What to do next
For the most accurate estimate, point C3X at a plan: c3x estimate --plan plan.json. It prices the resolved resources against a live catalog, and falls back to HCL parsing when no plan is available. The quickstart walks through both, and the CI/CD guide wires the plan flow into your pipeline.
Share this post
Try C3X on your own Terraform
Free and open source. No API key required. One command to install, one command to estimate.