Skip to content
Latchkey

infracost breakdown: Estimate Terraform Cost

infracost breakdown produces a monthly cost estimate for the resources in a Terraform project.

Infracost shows the dollar impact of infrastructure before it ships. breakdown is the base command: point it at a Terraform directory or plan and it prices each resource using public cloud rates.

What it does

infracost breakdown parses a Terraform directory, plan JSON, or state, matches each resource to the Infracost pricing database, and prints a table of monthly costs with a total. It needs an Infracost API key (free to obtain) to fetch prices, set as INFRACOST_API_KEY.

Common usage

Terminal
infracost auth login   # or set INFRACOST_API_KEY
infracost breakdown --path .
# price a saved plan for accuracy
terraform plan -out=tfplan.binary
terraform show -json tfplan.binary > plan.json
infracost breakdown --path plan.json

Options

FlagWhat it does
--path <dir|file>Terraform dir, plan JSON, or state file
--format <fmt>table, json, html
--out-file <file>Write the result to a file
--terraform-var-file <file>Pass a .tfvars file through to Terraform
INFRACOST_API_KEY envAuthenticates pricing lookups

In CI

Set INFRACOST_API_KEY as a secret; without it breakdown cannot fetch prices. Pricing a plan JSON (terraform show -json) is more accurate than a raw directory because variable values and counts are resolved. Generate --format json --out-file infracost.json so a later diff or comment step can reuse it.

Common errors in CI

"Error: No INFRACOST_API_KEY environment variable is set" means the secret is missing; run infracost auth login locally or set the key in CI. "could not parse Terraform" usually means HCL errors or a directory that needs terraform init first. Resources priced as "Monthly cost depends on usage" are normal for usage-based services, not errors.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →