Skip to main content
Use the CLI in a pull request check to show the monthly cost of a Terraform change and what the pull request’s CI runs have cost. This page lists the commands and the credential each one needs. The integration guides walk through complete workflows.

Choose a guide

In GitHub Actions, the CostGraph actions install the CLI for you. In another CI system, install the CLI and give the job an API key through COSTGRAPH_API_KEY. Refer to Use the key in a script or CI.

Requirements

For Terraform pricing, use a saved session or an API key with pricing:read. CI cost comments and existing-resource lookups through --plan need focus:read. GitHub comments also need a token with permission to comment on the pull request. Pass it through GITHUB_TOKEN or --github-token. Set --github-api-url for GitHub Enterprise Server.

Create the plan file

costgraph cost breakdown and costgraph cost diff read the JSON form of a Terraform plan.
Price the resources in that JSON file.
--format infracost-json writes Infracost’s format, so costgraph cost output can combine the result with an Infracost estimate. --out-file writes the result to a file instead of standard output. costgraph cost breakdown also looks up the same machine shape at other providers through the CostGraph Pricing API. The CLI sends your CostGraph credential to the Pricing API address in api.pricing_url, https://pricing.baselinehq.cloud by default. Add --no-alternatives to skip that lookup.

Pull request comments

Choose the command for either Terraform estimates or CI execution cost.

Preview CI cost

Both comment commands edit the comment they posted earlier on the same pull request. --behavior new posts a new comment each time. costgraph cost ci comment github supports --dry-run, which prints the comment instead of posting it.

Preview Terraform estimates

costgraph cost comment github has no dry-run option. Preview its content with costgraph cost output, --format github-comment, and the same --path and --plan files.

Command reference

Commands are shown without the costgraph prefix. Add --help for the complete flag list.

Terraform plan estimates

Run each command with the costgraph prefix.
command
Prices a Terraform plan JSON file. Requires a session or key with pricing:read.
command
Compares plan cost before and after a change. Requires a session or key with pricing:read.
command
Combines CostGraph and Infracost estimates. No CostGraph credential needed without --plan. With --plan, existing-resource lookups need focus:read.
command
Prints environment variables for using CostGraph prices with Infracost. No existing credential required.

GitHub pull request comments

Both commands need a GitHub token with permission to comment on the pull request.
command
Posts or updates the Terraform estimate comment. No dry-run option. --plan lookups need focus:read.
command
Posts or updates CI cost. Requires a session or key with focus:read. Use --dry-run to preview.

Estimate output flags

These flags control Terraform pricing results.
path
Selects the command’s input plan or estimate files. Check command help for its accepted input shape.
string
Selects the command’s output format. breakdown supports infracost-json; output supports github-comment.
path
Writes an estimate to a file instead of standard output.
boolean
Skips the alternative-provider lookup in cost breakdown.

Comment flags

Use these flags for the GitHub comment commands.
string
Sets the GitHub repository as owner/name.
integer
Sets the pull request number.
string
Supplies the comment token. Defaults to GITHUB_TOKEN when configured.
string
Selects a GitHub Enterprise Server API.
string
Uses new to post a separate comment rather than updating the existing one.
boolean
Previews CI cost comments only. Not supported by cost comment github.