Cost Estimation in Infrastructure as Code
Infrastructure as code makes it possible to see the cost of a change before it is deployed. This lesson explains how cost estimation from IaC plans works, how estimates are presented in pull requests, and what estimates can and cannot tell you.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how IaC plans enable cost estimation before deployment.
- Describe how a cost estimation tool works.
- Explain the value of cost estimates in pull requests.
- Identify the limitations of IaC cost estimates.
Infrastructure as code and plans
Infrastructure as code (IaC) tools, such as Terraform and OpenTofu, AWS CloudFormation, AWS CDK, Bicep and Pulumi, describe infrastructure in files that are versioned and reviewed like application code. Before changing real resources, most IaC tools can produce a plan or change set: a list of the resources that will be created, updated or destroyed, with their configuration. Terraform, for example, can save a plan and output it as JSON with terraform show -json.
Because the plan describes exactly what will change, it is the natural point to estimate the cost of the change, before any money is spent.
How estimation works
A cost estimation tool combines the plan with pricing data. The following steps describe the process.
-
Read the plan
Identify resources being created, changed and destroyed, and their attributes, such as instance type, region and storage size.
-
Price each resource
Look up the price for each resource's configuration from a pricing database or the provider's pricing API.
-
Apply usage assumptions
For usage-based charges, such as requests or data transfer, apply values from a usage file or defaults.
-
Compare
Calculate the monthly cost before and after the change and the difference.
-
Report
Present the result in the pull request, the pipeline log or a dashboard.
Infracost is a widely used open-source tool that does this for Terraform, with integrations for common CI/CD systems and source control platforms. Some IaC platforms provide similar estimates natively.
Estimating a change
Cost in the pull request
The most effective place to show an estimate is the pull request, where the change is reviewed. A comment such as "This change increases monthly cost by USD 1,240 (from USD 3,100 to USD 4,340), mainly from changing the database instance class" lets the author and reviewers discuss cost at the moment the change can still be adjusted. Over time, engineers develop a feel for the cost of their choices, which is the cultural goal of shifting left.
Limits of estimates
IaC estimates are valuable but approximate. The following list describes their main limitations.
- List prices: estimates usually use public prices and ignore commitment discounts, negotiated pricing and spot savings, so they overstate actual cost for covered usage.
- Usage-based charges: requests, data transfer, storage growth and serverless invocations cannot be read from the plan and need explicit usage assumptions.
- Resources outside IaC: anything created manually or by applications at runtime, such as autoscaled instances or objects written to storage, is not in the plan.
- Dynamic scaling: the plan shows minimum or desired capacity, not how far autoscaling will go.
Estimates are therefore best used to compare changes and catch large surprises, not as precise forecasts. Their accuracy improves when teams maintain usage assumption files for usage-based resources.
The following diagram shows what an estimate captures and what it misses.

Why estimates differ
Reading an estimate
A pull request changes a Terraform module so that each of 12 services gets its own NAT gateway instead of sharing one. The estimate shows an increase of about USD 360 a month in hourly gateway charges. Is the estimate complete?
No. The estimate captures the hourly charge of the 11 additional gateways, which can be read from the plan, but not the per-gigabyte processing charges, which depend on traffic. Those would be similar in total to today's if traffic is unchanged, but the reviewers should ask whether separate gateways are needed at all, and whether private endpoints could remove much of the processed traffic. A usage assumption for data processed would make the estimate more useful.
The estimate and the bill disagree
An estimate predicted USD 8,000 a month for a new service. The first full month's effective cost was USD 5,600. Was the estimate wrong?
Probably not in the way it seems. The estimate used list prices, while the service's instances are covered by the organization's commitments, so its effective cost is lower. Comparing the estimate with the service's ListCost in FOCUS data, rather than EffectiveCost, would show whether the resource assumptions were accurate. The team could also configure the estimate to show an approximate discounted figure.
Why do IaC cost estimates usually overstate the cost of usage covered by commitments?
Show answer
They are based on list prices and do not apply the organization's commitment or negotiated discounts.
Exam Tips
Remember for the exam
- Estimate cost from the IaC plan, before resources are created.
- Show the monthly cost difference in the pull request where the change is reviewed.
- Estimates use list prices and miss usage-based and runtime-created resources unless modeled.
- Use estimates to compare changes and catch surprises, not as exact forecasts.