DEV Community

Silas Stone
Silas Stone

Posted on

See Cloud Costs Directly Inside terraform plan with plancost

We've all experienced "Terraform Apply Anxiety."

You write your infrastructure code, the plan looks green, and you hit apply. A month later, the CFO (or your manager) slack messages you asking why the cloud bill just spiked by 40%.

For a long time, the solution to this was using external CLI tools. You know the drill: install a separate binary, wrap your CI pipeline, export the plan to JSON, parse it, and send it to a dashboard. It works, but it breaks the workflow. It feels like an add-on, not part of the infrastructure itself.

I built plancost to change that.

Today, I’m excited to announce the release of the plancost Terraform Provider.

 

What is plancost?

plancost allows you to estimate, track, and optimize cloud costs directly within your Terraform workflow.

Unlike other tools that function as CLI wrappers, plancost is a genuine Terraform Provider. This means:

  • Zero Extra Install: No brew install, no curl scripts, no separate binaries. It downloads with terraform init.
  • Native Experience: Cost estimates appear directly in your standard terraform plan output.
  • Cost as State: Cost data is stored in your state file, accessible to other resources.
  • Instant Diff: See exactly how much a change (like upgrading a VM SKU) will cost before you apply it.

 

Quick Start: Seeing is Believing

Let's see it in action. You don't need to sign up for anything to try it locally.

Here is a demo where I downgrade an Azure Kubernetes Service (AKS) node pool to save money. Notice how plancost catches the price difference instantly inside the plan output.

plancost demo

1. The Configuration

It takes seconds to set up. Just add the provider and the estimate resource to your main.tf.

terraform {
  required_providers {
    plancost = {
      source = "plancost/plancost"
    }
    azurerm = {
      source  = "hashicorp/azurerm"
    }
  }
}

# This single resource enables cost estimation for your module
resource "plancost_estimate" "this" {
  working_directory = abspath(path.module)
}
Enter fullscreen mode Exit fullscreen mode

 

2. The Result

When you run terraform plan, plancost scans your resources (like the AKS cluster below) and generates a cost breakdown.

terraform plan

The output is a native resource, so it shows up beautifully in your terminal or CI logs.

 

The Power of "Native Diff"

The real magic happens when you modify existing infrastructure. Because plancost is a resource, Terraform treats cost changes just like configuration changes.

In the example below, I am downgrading the AKS Node Pool from Standard_D2d_v4 to Standard_A2_v2. Terraform shows the config change, and plancost shows the money.

terraform plan diff

 

True "Cost as Code": Guardrails

Since we are inside the HCL configuration, we can enforce policies using code. No external policy engines (like OPA) are strictly necessary for basic checks.

You can define Guardrails to block a deployment if it exceeds your budget or if the cost spikes too aggressively.

resource "plancost_estimate" "this" {
  working_directory = abspath(path.module)

  # Fail the plan if total cost exceeds $1000
  guardrail {
    condition = "monthly_cost_budget"
    threshold = 1000
    action    = "block"
  }

  # Warn me if this specific plan increases cost by more than $50
  guardrail {
    condition = "monthly_cost_increase_amount"
    threshold = 50
    action    = "warning"
  }
}
Enter fullscreen mode Exit fullscreen mode

If you violate the guardrail, terraform plan will actually fail with a clear error message:

guardrail error

 

Simplifies CI/CD

This is my favorite part. If you have ever tried to integrate cost tools into GitHub Actions or GitLab CI, you know the pain of managing API keys, downloading binaries, and scripting comments.

With plancost, if your pipeline can run terraform plan, it can run cost estimation. It works out of the box in Atlantis, Terraform Cloud, GitHub Actions, Jenkins, etc.

 

What's Next?

We are launching with robust support for Microsoft Azure, covering over 500+ resources—from standard VMs and SQL Databases to complex networking components.

👉 Check out the full list here: Supported Resources Guide

Our roadmap includes:

  • 🚧 AWS Support (Coming soon)
  • 🚧 GCP Support
  • More Optimization Recommendations (Advanced right-sizing advice)

 

Try it out!

I’d love for you to try it out and let me know what you think. We are releasing this under the BUSL 1.1 license.

Drop a comment below if you have any feature requests or questions about the implementation! Happy coding (and saving)! 💸

Top comments (0)