FinOpsForge · Cloud cost guides, tools and comparisons. Sponsors are labelled.

Terraform Cost Estimation: Shift Left on Cloud Costs (2026)

// May 2026 // 10 min read

By the time a cloud resource appears on your bill, it's too late to easily remove it — it's been running for weeks and is probably depended on by other services. Shift-left cost management means catching expensive infrastructure decisions at the point they're made: in pull requests, before resources are provisioned.

What Is Shift-Left Cost Management?

Shift-left means moving cost visibility and controls earlier in the development lifecycle — into the infrastructure-as-code (IaC) review process, before resources are actually provisioned. An engineer writing Terraform should see the monthly cost impact of their changes before they merge, not after the next billing cycle.

Studies show it's 100x cheaper to fix a cost issue in a pull request than after it's been running in production for a month. Shift-left tools make this possible.

Infracost — The Leading Shift-Left Tool

Infracost is an open-source tool that parses Terraform plans and generates a cost estimate breakdown. It supports AWS, Azure, and GCP with 1,000+ resources priced. The free tier covers unlimited CLI usage; the Team tier ($50/month) adds CI/CD integrations, team policies, and Slack notifications.

# Install Infracost brew install infracost # macOS # or: curl -fsSL https://raw.githubusercontent.com/infracost/infracost/master/scripts/install.sh | sh # Authenticate infracost auth login # Generate cost breakdown for Terraform directory infracost breakdown --path . # Compare two branches infracost diff --path . --compare-to /tmp/infracost-base.json

Example output when a developer adds an aws_db_instance:

Project: my-terraform-repo + aws_db_instance.main Instance type db.r5.2xlarge Database engine PostgreSQL Multi-AZ true Cost breakdown: Database instance $876.00/mo Storage (500 GB gp2) $57.50/mo Monthly cost change: +$933.50

CI/CD Integration

The real value of Infracost comes from integrating it into your pull request workflow. Every PR that changes Terraform gets an automatic cost estimate comment:

# GitHub Actions: infracost.yml name: Infracost on: [pull_request] jobs: infracost: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: infracost/actions/setup@v2 with: api-key: ${{ secrets.INFRACOST_API_KEY }} - name: Generate cost estimate run: | infracost breakdown --path=. --format=json --out-file=/tmp/infracost.json - uses: infracost/actions/comment@v1 with: path: /tmp/infracost.json behavior: update

Cost Policies with OPA

Open Policy Agent (OPA) can evaluate Infracost diff output against a cost policy. The example below defines a policy; the GitHub Actions workflow shown above posts a cost comment but does not run this policy.

# Example Rego v0 policy: identify changes adding >$1000/month package infracost deny[msg] { monthly_cost := input.projects[_].diff.totalMonthlyCost to_number(monthly_cost) > 1000 msg := sprintf("PR adds $%.2f/month — exceeds $1000 threshold. Get approval.", [to_number(monthly_cost)]) }

This example uses Rego v0 syntax. With OPA 1.x, use a v0-compatible execution mode or deliberately migrate the policy to Rego v1 syntax. Blocking a pull request requires a CI step that evaluates the policy, fails on a denial, and is required before merge. The workflow above does not configure that enforcement.

Terraform Cost Best Practices

  • Use variables for instance types — makes right-sizing changes a one-line diff instead of hunting through modules
  • Tag everything at the resource level — Terraform makes consistent tagging trivial with default_tags on AWS providers
  • Separate dev/staging/prod workspaces — enforce smaller instance types in non-production via workspace-conditional variables
  • Use data sources to reference existing resources — avoid provisioning duplicate infrastructure (VPCs, security groups) that runs parallel costs
  • Review terraform plan output before apply — new resources added to plans should be questioned: is this intentional? Is the size appropriate?

// FAQ

Is Infracost accurate enough to rely on?
Accuracy is 85–95% for common resources (EC2, RDS, S3, EKS). Less accurate for: data transfer costs (usage-based), Lambda (highly variable), and newer resource types. It's a directional signal for pull requests — not a replacement for your actual bill.
Does Infracost work with Terragrunt or OpenTofu?
Infracost documents Terraform support and automatic Terragrunt project detection with infracost scan. Its supported-resources overview lists Pulumi as planned, rather than supported. Confirm OpenTofu compatibility and CLI options against the documentation for the version you use.

Try Infracost Free

Explore product features and check current details with the vendor.

Visit Site →

// Recommended Reading

// related guides