skip to content

On Infracost CLI 2.x, what happens to an old script running `infracost breakdown --path . --format json --out-file base.json` and `infracost comment github`?

level: middleimportance: nice to knowfreq 15%

answer

  1. one fails loudly, one quietly
  2. a hidden shim
  3. which flags survive the translation
  4. the replacement the error names

basics

~20 s

On Infracost CLI 2.x, breakdown warns and runs scan, keeping only the path and silently dropping the format and output flags, so no JSON file appears. The comment command fails outright and points to infracost ci setup.

solid answer

~40 s

The two fail differently, and the quiet one is the dangerous one. `infracost breakdown` is a hidden shim: it prints a deprecation warning to stderr and runs `infracost scan`, turning `--path` into the positional target and silently dropping every other flag. So `--format json` and `--out-file` vanish, human text goes to stdout, `base.json` is never written, and a later `infracost diff --compare-to base.json` fails on the missing file. `infracost comment` simply errors, telling you to configure an integration with `infracost ci setup`. `generate` points to `infracost setup`, while `configure`, `output` and `upload` are just gone. `infracost diff` is not retired: it is a live 2.x command, though its old `--path`, `--format` and `--out-file` flags are deprecated. The current spelling is `infracost scan . --json > base.json`.

code

bash · 8 lines
bash
# The target is an argument and the JSON goes to stdout
infracost scan . --json > base.json

# After the code change, compare with that baseline
infracost diff . --compare-to base.json

# Pull-request comments come from an integration, not a script step
infracost ci setup

go deeper

for a junior

Recall that the current everyday commands are infracost scan and infracost inspect, and that breakdown, comment and output come from the older CLI. Be ready to say which repository each generation lives in.

for a middle

Explain why breakdown succeeds while dropping flags, why comment errors, and that diff is still current with compare-to. Trace a stale script step by step to the missing baseline file.

for a senior

Show how you would find silent drift during an upgrade: dropped var files and usage files change the estimate with no failure. Compare one estimate before and after, and pin the version you run.

for a principal

Treat a vendor's CLI generation change as a platform migration: an inventory of pipelines, one owner and a before-and-after comparison, instead of leaving each team to discover that its cost figure quietly changed.

## Two generations of one tool Infracost has two CLIs that share a binary name. The **0.10 generation** lives in the `infracost/infracost` repository. The **2.x generation** lives in `infracost/cli`; this answer is checked against 2.18.3. Scripts, blog posts and many memories still use the old commands, so a pipeline can upgrade under you and change meaning. The 2.x CLI keeps hidden entries for old command names so they respond with something useful. They do not all respond the same way. ## What each old command does now | Old command | On CLI 2.x | Use instead | |---|---|---| | `infracost breakdown` | Warns on stderr, then runs a scan; only `--path` survives | `infracost scan [path]` | | `infracost diff` | Still a live command; some old flags are deprecated | `infracost diff [path] --compare-to base.json` | | `infracost comment` | Error naming the replacement | `infracost ci setup` | | `infracost generate` | Error naming the replacement | `infracost setup` | | `infracost configure` | Error: removed | Nothing named | | `infracost output` | Error: removed | Nothing named | | `infracost upload` | Error: removed | Nothing named | The errors are the easy case, because the job goes red and the message says what to do. The shim is the hard one. ## Why the shim is the trap Trace the script from the question: 1. `infracost breakdown --path . --format json --out-file base.json` starts. Flag parsing is off for the shim, so the arguments go to a small translator. 2. The translator keeps `--path .` as the scan target. Every other flag is dropped with no message of its own. 3. The scan runs and prints the human summary to stdout. The step exits 0, since a warning is not a failure. 4. `base.json` was never created. A following `infracost diff --compare-to base.json` fails with a message about opening that file, one step away from the real cause. The same translation swallows `--usage-file`. A script passing usage values through the old flag still gets a scan and a green step, but the estimate no longer uses that file. Nothing fails; the number just changes. ## What survived in `infracost diff` `diff` is a current command, shown in the CLI's help under analysis commands. It compares the code now against a baseline, which is a saved `infracost scan --json` file given by `--compare-to`, or the last cached scan of that path. Its old flags are kept so existing scripts get a deprecation notice rather than an unknown-flag error: - `--path` still works; pass the path as an argument instead. - `--format json` still gives JSON; use `--json` instead. - `--out-file` still writes the file; redirect stdout instead. - `--show-skipped` is accepted and ignored, because all resources are now shown. - `--terraform-var-file` is accepted and ignored, and its notice says it is no longer supported. A script relying on it may get a different estimate from before. ## Other things that moved - **The login.** The old CLI used `INFRACOST_API_KEY`. The current one logs in from `INFRACOST_CLI_AUTHENTICATION_TOKEN` or `infracost auth login`. The generated CI job still names its secret `INFRACOST_API_KEY` but passes it in under the new variable. - **Usage values.** `infracost scan` has no `--usage-file` flag, and the `--sync-usage-file` flow does not exist in 2.x. Usage files are named in `infracost.yml`. - **The scan target.** `infracost scan --path .` is not a thing: `scan` takes its target as an argument and has no `--path` flag. - **A lookalike binary.** The CI image's `infracost-ci scan --path .` does take `--path`. `infracost-ci` is a separate program from `infracost`, so a line copied from a generated CI file will not run on the CLI. - **Pull-request comments.** There is no comment command to call from your own script. `infracost ci setup` connects the repository to the app integration, or with `--pipeline` writes a CI config. It needs an interactive login and refuses to run on the token variable. ## How to migrate safely Search every pipeline for old command names and treat `breakdown` as the priority, because it is the one retired command that will not tell you with a failure. Compare one estimate before and after, since dropped var files and usage files change the figure without any error.

  • A job still sets only `INFRACOST_API_KEY` after moving to Infracost CLI 2.x. What happens?
    On its own that variable does not log the CLI in, so the scan fails asking for `INFRACOST_CLI_AUTHENTICATION_TOKEN` or `infracost auth login`. The CLI adopts the old key only as a self-hosted pricing key, and only when `INFRACOST_PRICING_API_ENDPOINT` is also set, because that pair clearly means a legacy self-hosted setup.
  • Why can `infracost diff` refuse a baseline file you give it?
    It checks. It rejects a file with no projects, rejects a file that is itself `infracost diff` output because its costs would read as zero, and rejects a baseline priced in another currency. A critical diagnostic on either side also stops it, since a project that failed to parse would read as a mass deletion.

  • Every old Infracost command now fails with a clear error, so a stale script cannot pass unnoticed.
  • infracost diff was removed in the 2.x CLI along with comment and output.
  • The breakdown shim passes its flags to scan, so format json still writes a JSON file.
  • infracost scan --path . is the current way to name the scan target.
  • Setting INFRACOST_API_KEY alone in a job is enough to log the 2.x CLI in.