> ## Documentation Index
> Fetch the complete documentation index at: https://docs.costgraph.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Estimate Terraform and CI costs with the CostGraph CLI

> Price a Terraform plan, combine it with Infracost, and post plan and CI costs on GitHub pull requests

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

* [Terraform cost on pull requests](https://docs.costgraph.ai/costgraph/integrations/infracost.md) prices a Terraform plan, combines it with an Infracost estimate, and posts one comment. Its [other CI systems](https://docs.costgraph.ai/costgraph/integrations/infracost.md#estimate-terraform-costs-in-other-ci-systems) section shows the CLI commands outside GitHub Actions.
* [CI cost on pull requests](https://docs.costgraph.ai/costgraph/integrations/github.md#show-ci-cost-on-pull-requests) posts what a pull request's GitHub Actions runs have cost.

In GitHub Actions, the CostGraph actions install the CLI for you. In another CI system, [install the CLI](https://docs.costgraph.ai/costgraph/cli/install.md#install) and give the job an API key through `COSTGRAPH_API_KEY`. Refer to [Use the key in a script or CI](https://docs.costgraph.ai/costgraph/cli/api-keys.md#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.

```shell theme={null}
terraform plan -out plan.out
terraform show -json plan.out > plan.json
```

Price the resources in that JSON file.

```shell theme={null}
costgraph cost breakdown --path plan.json
```

`--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.

```shell theme={null}
costgraph cost ci comment github --repo owner/name --pull-request 12 --dry-run
```

### 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.

**cost breakdown** `command`

Prices a Terraform plan JSON file. Requires a session or key with `pricing:read`.

**cost diff** `command`

Compares plan cost before and after a change. Requires a session or key with `pricing:read`.

**cost output** `command`

Combines CostGraph and Infracost estimates. No CostGraph credential needed without `--plan`. With `--plan`, existing-resource lookups need `focus:read`.

**cost setup-infracost** `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.

**cost comment github** `command`

Posts or updates the Terraform estimate comment. No dry-run option. `--plan` lookups need `focus:read`.

**cost ci comment github** `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** `path`

Selects the command's input plan or estimate files. Check command help for its accepted input shape.

**--format** `string`

Selects the command's output format. `breakdown` supports `infracost-json`; `output` supports `github-comment`.

**--out-file** `path`

Writes an estimate to a file instead of standard output.

**--no-alternatives** `boolean`

Skips the alternative-provider lookup in `cost breakdown`.

### Comment flags

Use these flags for the GitHub comment commands.

**--repo** `string`

Sets the GitHub repository as `owner/name`.

**--pull-request** `integer`

Sets the pull request number.

**--github-token** `string`

Supplies the comment token. Defaults to `GITHUB_TOKEN` when configured.

**--github-api-url** `string`

Selects a GitHub Enterprise Server API.

**--behavior** `string`

Uses `new` to post a separate comment rather than updating the existing one.

**--dry-run** `boolean`

Previews CI cost comments only. Not supported by `cost comment github`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.