Skip to content
Latchkey

infracost diff: Show the Cost of a Change

infracost diff reports how much a Terraform change adds to or removes from the monthly bill.

For a PR, the total cost matters less than the delta. infracost diff compares the proposed state against a prior breakdown and shows only what the change costs.

What it does

infracost diff prices the current configuration and compares it to a baseline produced by an earlier breakdown --format json. It prints added, removed, and changed resources with the monthly difference and an overall delta. This is the number you surface on a pull request.

Common usage

Terminal
# baseline from the default branch
infracost breakdown --path . --format json --out-file base.json
# after checking out the PR branch
infracost diff --path . --compare-to base.json

Options

FlagWhat it does
--path <dir|file>The changed configuration to price
--compare-to <file>Baseline JSON from a prior breakdown
--format jsonEmit machine output for a later comment step
--out-file <file>Save the diff for the comment command

In CI

The standard PR flow: run breakdown --format json on the base branch to make base.json, then diff --compare-to base.json on the PR branch, then post it. The official infracost/actions/setup action plus infracost diff covers this; many teams use it so reviewers see the cost impact inline.

Common errors in CI

"compare-to file ... does not exist" means the baseline JSON was not produced or not passed between jobs; persist it as an artifact. "the infracost JSON is not the right version" means base.json was made by a different Infracost version; regenerate it with the same binary. A diff of zero on a real change usually means both sides priced the same path; confirm the base was the unchanged branch.

Related guides

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