CLICommands

l4 estimate

l4 estimate parses the Terraform files in your workspace and estimates the monthly cost of the resources they define. It runs entirely locally and needs no terraform plan. Point it at directories, individual .tf files, or a mix.

l4 estimate
l4 estimate ./infra/
l4 estimate main.tf variables.tf

Flags

FlagDescription
--region <r>AWS region for pricing (default us-east-1)
--gcp-region <r>GCP region (default: auto-detect or us-central1)
--azure-region <r>Azure region (default: auto-detect or eastus)
--var <key=value>Terraform variable (repeatable)
--var-file <path>Terraform variable file (repeatable)
--download-modulesDownload remote modules for accurate estimates (default true)
--out-file <path>Save resource snapshot for later use with l4 diff
--fail-above <amount>Exit code 2 if monthly cost exceeds this threshold
--formattable, json, or github-comment (default table)
Pricing is regional, and --region does not auto-detect the way --gcp-region and --azure-region do. Leave it out and every AWS resource is priced in us-east-1, which returns a plausible total that is wrong for any other region.

Global flags apply, including --quiet and --token. See CLI overview.

CI guardrail pattern

Fail the build when the estimated monthly cost is above $500:

l4 estimate --fail-above 500 -q ./infra/
A wired gate exits 2 once the estimate goes over the threshold. That is the guardrail firing rather than the command breaking, and the two carry different codes, so a job can branch on the difference. Exit codes has the full set.

--fail-above gates on the total here, so a workspace that sits above the line fails every build, whether or not the change moved it. l4 diff gates on the delta instead.

Saving a snapshot for later comparison

Outside a git repo, save the current estimate as a baseline you can diff against later:

l4 estimate --out-file baseline.json ./infra/
# ... make changes ...
l4 diff baseline.json ./infra/

In a git repo you need no snapshot at all. See l4 diff for the default baseline.

Posting to a pull request

The github-comment format is what the LevelFour GitHub Action uses. Post it by hand with:

l4 estimate --format github-comment ./infra/ \
  | gh pr comment "$PR_NUMBER" --body-file -
  • l4 diff compares an estimate against a branch or a saved baseline
  • CI/CD integration has the GitHub Actions and GitLab CI jobs that run this command
  • Output formats covers the global --json, --jq, --template and --quiet flags