DevOps Tools
Infracost Explained: How to See Terraform Costs Before You Launch
Tired of getting shocked by your monthly cloud bill? This article introduces Infracost, a free tool that shows you the cost of your Terraform projects before you deploy them. Find out how it works and how it can help your team make smarter, cost-aware decisions right from your code editor and pull requests.
Infracost Explained: How to See Terraform Costs Before You Launch

Cloud cost surprises are a common source of friction for engineering teams. An accidental change—a larger instance type, a misconfigured storage class—can lead to thousands of dollars in unexpected charges, discovered only when the monthly bill arrives. What if you could see the financial impact of your infrastructure changes before you deploy them? That's the problem Infracost solves. Infracost is a powerful open-source tool that integrates directly into your Terraform workflow to provide clear, actionable cloud cost estimates, shifting cost visibility left and empowering developers to make cost-aware decisions.

What is Infracost and How Does It Work?

Infracost is a command-line interface (CLI) tool and SaaS platform that shows cloud cost estimates for Infrastructure as Code projects, with a primary focus on Terraform. It lets engineers see a detailed cost breakdown and understand the financial impact of their changes directly in the terminal, their code editor, or within pull requests. This proactive approach provides a safety net, allowing teams to discuss costs as a standard part of the code review process.

The process is designed to be both simple and secure:

  1. Parse IaC Code: Infracost's CLI parses your Terraform HCL code directly. It extracts only the cost-related parameters, such as instance types, disk sizes, or auto-scaling configurations. This method is fast and does not require a full terraform plan or any cloud credentials.

  2. Retrieve Cloud Prices: The CLI sends these cost-related parameters to the Infracost Cloud Pricing API. This API contains over 3 million public prices from AWS, Azure, and Google Cloud, which are updated weekly. Crucially, no secrets, cloud credentials, or sensitive configuration data are sent to the API.

  3. Calculate Costs: The CLI receives the pricing data and calculates the estimated monthly cost for each resource. It can also evaluate the code against FinOps best practices and tagging policies you've configured.

  4. Display the Breakdown: The results are displayed in a clear, human-readable format, showing what's being added, changed, or removed, and the corresponding cost delta.

Key Features and Capabilities

Infracost offers a suite of tools designed to integrate cost visibility into every stage of the development workflow, from writing code to reviewing pull requests.

Infracost CLI: Your Local Cost Companion

The core of Infracost is its CLI, which provides two primary commands: breakdown and diff.

  • infracost breakdown: This command scans your current Terraform project and generates a table showing the estimated monthly cost for each resource defined in your code. It's a quick way to get a snapshot of your project's total cost. You can also output this in JSON format for integration with other tools.

  • infracost diff: This is one of Infracost's most powerful features. It compares the cost of your infrastructure before and after a code change. By creating a baseline JSON file from your main branch and then running a diff against your feature branch, you can see exactly how your changes will increase or decrease the monthly bill.

Infracost VSCode Extension

For even earlier feedback, the Infracost VSCode extension brings cost estimates directly into the code editor. As an engineer writes or modifies Terraform code, the extension displays the estimated cost for that resource right above the code block. This replaces the need to manually consult cloud provider pricing pages or calculators, saving time and catching costly typos in real-time.

CI/CD Integration: Cost Awareness in Pull Requests

The most impactful use of Infracost is within a CI/CD pipeline. By integrating with systems like GitHub Actions, GitLab, or Azure Repos, Infracost can automatically run a cost analysis on every pull request. It then posts a comment directly in the PR, showing a summary of the cost changes. For example, a comment might state, "This change will increase costs by 25%," along with a detailed breakdown of which resources were added or modified. This makes cost a first-class citizen in the code review process, alongside code quality and security scans.

Infracost Cloud: Governance and FinOps at Scale

While the open-source CLI provides cost visibility, Infracost Cloud is a SaaS product that builds on this foundation to enable FinOps governance at scale. It allows team leads, managers, and FinOps practitioners to:

  • Set Guardrails and Policies: Define cost policies and best practices that are automatically checked against every pull request. For example, you can create a policy to recommend switching from AWS gp2 volumes to the cheaper and more performant gp3 volumes.

  • Enforce Tagging: Create tagging policies to ensure all resources are correctly labeled for cost allocation and governance.

  • Centralized Dashboards: Gain a centralized view of cost estimates across all projects and teams, track trends, and identify optimization opportunities.

  • Support for Discounts: Input enterprise discount programs (EDP) or enterprise agreements (EA) to get more accurate cost estimates that reflect your negotiated pricing.

Why Use Infracost? The Benefits of Proactive FinOps

Integrating Infracost into your workflow provides tangible benefits that align directly with the goals of a modern FinOps practice.

  • No More Budget Surprises: By catching expensive changes before they are deployed, you eliminate the shock of an unexpectedly high cloud bill.

  • Empower Developers with Cost Insights: Infracost gives engineers the data they need to make cost-effective decisions without slowing them down. It makes them partners in cost management rather than just cost centers.

  • Enable Cost-Aware Reviews: Pull request comments facilitate conversations about cost trade-offs between team members, architects, and managers, leading to better architectural decisions.

  • Automate FinOps Governance: Infracost Cloud allows you to codify and automate your organization's financial best practices, ensuring they are applied consistently across all teams and projects.

Conclusion

Infracost is more than just a cost calculator; it's a cultural tool that embeds financial awareness directly into the engineering process. By providing immediate, actionable cost feedback where developers live—in their editor, terminal, and pull requests—it transforms cloud cost management from a reactive, top-down mandate into a proactive, collaborative effort. Whether you're an individual developer wanting to understand the cost of your code or a large enterprise looking to implement FinOps governance at scale, Infracost provides the tools to bring cloud costs out of the dark and into the light.

See, Understand, Optimize -
All in One Place

Atler Pilot decodes your cloud spend story by bringing monitoring, automation, and intelligent insights together for faster and better cloud operations.