Infracost for CI Cost Guardrails

Cloud bills are operational data. A sudden spend jump can point to runaway autoscaling, mis-sized storage, forgotten test environments, or infrastructure code that looked harmless during review. Infracost helps teams catch those changes before deployment.
What Is Infracost?
Infracost is an open source cloud cost intelligence tool for engineers, CI/CD pipelines, editors, and AI coding agents. It supports Terraform, Terragrunt, CloudFormation, and AWS CDK, with estimates across AWS, Azure, and Google Cloud.
The core workflow is simple: scan infrastructure code, calculate a cost estimate, and surface the diff where engineers already work. Infracost can show estimates in the terminal, comment on pull requests, provide editor hints, and expose skills for coding agents.
Key Features
- Pull request cost diffs: reviewers see monthly cost changes before merge.
- Policy guardrails: teams can enforce tagging, budget, region, and resource rules.
- Editor feedback: engineers see cost hints while editing IaC files.
- AI agent skills: coding agents can price resources and scan projects against FinOps policies.
- Broad cloud coverage: the project documents support for more than 1,100 resources across major cloud providers.
Installation
Install the CLI first:
brew install infracost
On Linux:
curl -fsSL https://raw.githubusercontent.com/infracost/cli/master/scripts/install.sh | sh
Then run setup:
infracost setup
The docs note that Infracost parses projects locally and does not change IaC state or cloud resources.
Usage In CI
Start with a local scan:
cd my-terraform-project
infracost scan
For production workflows, wire Infracost into CI so every infrastructure pull request gets a cost diff. A reviewer should be able to answer three questions quickly:
- Did this change increase monthly cost?
- Which resource caused the increase?
- Does the change violate any budget, tagging, or preferred-region policy?
That review loop is useful when AI agents generate infrastructure changes. The agent can move quickly, but the pipeline should still check cost, policy, and operational intent before merge.
Operational Tips
Treat cost diffs like reliability signals. Route large increases to the same owners who review capacity, scaling, and service limits.
Use tags and cost categories consistently. Infracost can only make useful policy decisions when the IaC carries enough ownership context.
Keep forecasted cloud bills and IaC estimates separate. AWS Budgets and Cost Anomaly Detection still help after deployment, but CI guardrails catch mistakes earlier.
Conclusion
Infracost is a practical control for teams that review infrastructure as code. It does not replace billing alerts, but it gives SRE and platform teams an earlier signal: this pull request changes spend, and here is where the change comes from.
If you are building reliable, AI-assisted operations, Akmatori helps teams automate infrastructure workflows and incident response. Backed by Gcore, we are building tools for modern SRE and platform teams.
