# Infracost

> For AI agents: the complete documentation index is at https://buddy.works/llms.txt

Connect Buddy to Infracost and estimate the monthly cost of Terraform and OpenTofu plans in your pipelines.

## What is Infracost?

Infracost estimates resource costs from Terraform and OpenTofu plans using pricing data from AWS, Azure, and Google Cloud. It calculates the estimated monthly infrastructure cost before and after the planned changes.

The Infracost integration enables [cost estimation](https://buddy.works/docs/terraform/cost-estimation.md) in the **Terraform Plan**, **Terraform Drift Detection**, and **Terraform Cost Estimation** actions. The run displays estimated resource costs and exports cost totals as variables for use in trigger conditions, approval conditions, and notifications.

## Obtaining an Infracost CLI token

Buddy needs a CLI token from Infracost Cloud. Infracost issues this token for the CLI and for CI/CD integrations.

1. Sign up at [infracost.io](https://www.infracost.io "seo-nf") and log in to Infracost Cloud.

2. On first login, create an organization. Keys and run limits belong to the organization.

![Creating an organization in Infracost Cloud](https://buddy.works/docs/integrations/infracost/infracost-create-organization.png)

3. Open **Org settings** and go to **CLI tokens**. Copy the token from the **CLI v0.1 token** section or create a new token in the **CLI v2 tokens** section. Buddy supports both token versions.

![CLI tokens tab in the Infracost Cloud organization settings](https://buddy.works/docs/integrations/infracost/infracost-cli-tokens.png)

## Adding the integration in Buddy

1. In Buddy, go to the Integrations tab and click **New integration**.

2. Select **Infracost** from the list.

3. Fill in the form:

- **Name** and **ID** - the name of the integration and its identifier. You enter the identifier in the `integration` field in YAML
- **Scope** - whether the integration is available in the whole Workspace, in one Project, or in a selected Environment
- **API key** - the CLI token from Infracost Cloud

4. Click **Add a new integration**.

![Infracost integration form with the API key](https://buddy.works/docs/integrations/infracost/infracost-integration-form.png)

Buddy stores the CLI token as an encrypted secret and passes it to the action only during execution.

> **Info**
>
> In the Permissions tab, you can configure who can access and use the integration.

## Cost estimation in a pipeline

In the **Terraform Plan** or **Terraform Drift Detection** action, on the Run tab, select **Cost estimation** and choose the integration. You can also add a separate **Terraform Cost Estimation** action. In YAML:

```yaml
- action: Plan
  type: TERRAFORM_PLAN
  tool: OPENTOFU
  version: 1.12.6
  working_directory: infra
  cost_estimation:
    enabled: true
    integration: infracost
```

Each action with cost estimation enabled counts toward the Infracost organization's CI/CD run limit, including actions executed in pull request runs.

> **Info**
>
> All options are described in [Cost estimation](https://buddy.works/docs/terraform/cost-estimation.md), and the YAML parameters are in the action reference for [Terraform Plan](https://buddy.works/docs/yaml/yaml-actions/terraform-plan.md) and [Terraform Cost Estimation](https://buddy.works/docs/yaml/yaml-actions/terraform-cost-estimation.md).


---
Original source: https://buddy.works/docs/integrations/infracost