infracost
Infracost shows cloud cost estimates for Terraform, CloudFormation, and AWS CDK before you deploy — in your terminal, editor, AI coding agent, and pull requests.
Infracost is a command-line tool that turns Terraform, Terragrunt, CloudFormation, and AWS CDK code into a concrete monthly dollar estimate before anything gets applied. Instead of waiting for a cloud bill at the end of the month, engineers run infracost breakdown against a project directory or plan file and get a resource-by-resource cost table, or run infracost diff in CI to see exactly how much a pull request will change spend. It is written in Go and distributed as a single static binary, installable via Homebrew, Chocolatey, or a shell script, with no cloud credentials required for the common case.
Under the hood, Infracost implements its own HCL parser and dependency graph evaluator (internal/hcl) that resolves Terraform modules, variables, and outputs statically — without shelling out to terraform plan or touching real cloud accounts — falling back to invoking the Terraform CLI only when explicitly requested via --terraform-force-cli. CloudFormation and synthesized AWS CDK templates are parsed with the awslabs/goformation library. Resolved resources are matched against per-cloud-provider cost models (over 1,100 resource types across AWS, Azure, and Google Cloud, in internal/resources) and priced through Infracost’s hosted GraphQL Cloud Pricing API, with bundled infracost-usage-defaults.*.yml files supplying realistic default usage for consumption-priced resources like S3, Lambda, and DynamoDB that would otherwise show $0.
The CLI is the core of a wider toolkit: a Language Server powers cost-lens extensions for VS Code, JetBrains IDEs, Neovim, and Zed; a separate agent-skills package plugs cost and FinOps policy checks into Claude Code, Cursor, and other AI coding agents as they generate infrastructure code; and infracost comment posts cost-diff comments directly on GitHub, GitLab, Bitbucket, and Azure Repos pull requests. Infracost Cloud, a hosted SaaS dashboard, layers team-wide tagging policies, spend guardrails, and cross-project visibility on top of the same engine, but the CLI and estimation engine themselves remain fully open source under Apache 2.0.
As of the 2.0 restructuring, this repository is described by the maintainers as the ecosystem’s front door — the actual estimation engine (HCL parsing, resource pricing, output formatting) still lives here, while editor extensions, the language server, and agent skills have been split into sibling repositories under the same GitHub organization.
What You Get
- A single static Go binary (
infracost) withbreakdown,diff,output,upload, andcommentsubcommands covering local estimation through to CI/CD integration. - A custom HCL graph evaluator that resolves Terraform modules, variables, and outputs statically, so cost estimates work without applying infrastructure or holding cloud credentials.
- Pricing coverage for over 1,100 resource types across AWS, Azure, and Google Cloud, backed by Infracost’s hosted GraphQL Cloud Pricing API.
- Built-in output formats — table, JSON, HTML, Markdown, and Slack message — plus native PR comment posting for GitHub, GitLab, Bitbucket, and Azure Repos.
- Bundled usage-default files that model consumption-priced resources like S3, Lambda, and DynamoDB realistically instead of returning zero-cost estimates.
- A companion ecosystem — editor extensions (VS Code, JetBrains, Neovim, Zed) via a shared Language Server, and an
agent-skillspackage for AI coding agents like Claude Code and Cursor.
Common Use Cases
- Wiring
infracost diffinto CI so every Terraform pull request shows a dollar cost delta before it can merge. - Running
infracost breakdown --path .locally to get a full resource-level cost table before opening a PR. - Enforcing FinOps tagging policies and spend guardrails organization-wide through Infracost Cloud alongside the open-source CLI.
- Checking cost and policy compliance on AI-agent-generated Terraform or CDK code via the
agent-skillsintegration. - Getting inline cost hints and hover breakdowns while editing
.tfor CloudFormation files through the VS Code, JetBrains, Neovim, or Zed extensions.
Under The Hood
Architecture
Infracost is a cobra-based CLI (cmd/infracost) whose PersistentPreRunE hook wires up a shared config.RunContext that flows through every subcommand. Provider detection (internal/providers/detect.go) routes a project to either the Terraform or CloudFormation provider, which produce schema.Resource/schema.Project primitives consumed uniformly downstream. The distinguishing layer is internal/hcl, a custom graph evaluator (graph_vertex_module_call.go, graph_vertex_resource.go, graph_vertex_variable.go, etc.) that statically resolves module calls, variables, and outputs into a synthesized plan, avoiding a real terraform plan invocation in the default path. Resolved resources are matched against per-cloud CoreResource implementations (internal/resources/aws, azure, google, over 120 files per cloud), priced via internal/prices, and rendered through internal/output’s format-specific writers. This is a solid, clearly layered design; the risk is that internal/resources has become a very large package-per-cloud with hundreds of individual resource files, so changing the CoreResource interface would ripple broadly.
Tech Stack
Written in Go 1.25, using spf13/cobra and pflag for the CLI surface, a bespoke HCL evaluator built on hashicorp/hcl and zclconf/go-cty rather than reusing Terraform’s own graph internals, dave/dst for Go AST manipulation in tooling, and awslabs/goformation for CloudFormation/CDK parsing. AWS SDK v2 clients support live resource lookups where needed, Rhymond/go-money handles currency formatting, and logging runs through sirupsen/logrus and rs/zerolog. CI (GitHub Actions go.yml) builds with the Go toolchain, runs golangci-lint v2, checks Terraform formatting, and exercises a Terragrunt-based integration path; releases ship as cross-platform binaries plus Alpine/Wolfi Docker images.
Code Quality
The repository carries an extensive suite of Go test files spanning the HCL evaluator, resource cost calculations, and output formatters, using stretchr/testify’s assert/require alongside golden-file-style testdata directories for output regression testing. Errors are propagated explicitly with wrapped fmt.Errorf/pkg/errors calls and surfaced through a dedicated clierror package with panic recovery in the CLI entrypoint, rather than being silently swallowed. CI enforces golangci-lint with a strict timeout and Terraform format checks on every push and pull request, indicating an actively maintained quality bar.
What Makes It Unique
Rather than requiring a live terraform plan (and therefore real cloud credentials and applied state) to estimate cost, Infracost’s static HCL graph evaluator resolves modules and variables offline, letting it estimate cost pre-deploy, in CI, in editors, and even inside AI coding agent workflows with no cloud access at all. Paired with a hosted pricing API covering 1,100+ resource types and usage-default modeling for consumption-based services, this static-evaluation-first approach is the clearest technical differentiator versus tools that depend on a live plan or ongoing cloud API polling.
Self-Hosting
Licensing Model Apache License 2.0 — the CLI and the entire cost-estimation engine (HCL evaluator, resource pricing, output formatting) are fully open source, with the source code available to inspect, modify, and self-host.
Self-Hosting Restrictions
No restrictions were found in the codebase itself. Running infracost breakdown or infracost diff locally or in CI only requires a free API key for Infracost’s hosted Cloud Pricing API (rate-limited on the free tier, not a paid license) — no license key gates any CLI functionality.
Enterprise Features Infracost Cloud, described in the README as a separate hosted SaaS dashboard, adds team-wide tagging policies, spend guardrails, and cross-project/PR visibility on top of the same CLI output — these are additive cloud-only capabilities rather than features disabled in the open-source CLI.
Cloud vs Self-Hosted The CLI’s core estimation, diffing, and output generation work identically self-hosted or via Infracost Cloud; Infracost Cloud’s incremental value is organization-wide policy enforcement and dashboarding rather than materially different estimation capability.
License Key Required No — the CLI runs fully self-hosted with only a free Cloud Pricing API key needed to fetch prices.
Related Apps
Ollama
AI Development · Developer Tools
Run Llama, Gemma, DeepSeek, and other open LLMs on your own machine with one command and an OpenAI-compatible API.
Ollama
MITDify
No Code Platforms · AI Development · Developer Tools
Visual LLM workflow platform with RAG pipelines, agent capabilities, and model management for building production AI applications.
Dify
OtherFirecrawl
AI Development · Developer Tools
Turn any website into clean, LLM-ready data with a single API call — no proxy headaches, no scraping complexity.