How to Use Cost Estimation in Terraform Cloud
To use cost estimation in
Terraform Cloud, enable the Cost Estimation feature in your workspace settings and run a plan. Terraform Cloud then analyzes the planned resources and provides an estimated cost report before applying changes.Syntax
Cost estimation in Terraform Cloud is enabled via workspace settings and does not require special Terraform code. The key steps are:
- Enable Cost Estimation in the workspace.
- Run
terraform planor a plan via Terraform Cloud UI. - View the cost estimate report generated automatically.
This feature integrates with your Terraform runs and analyzes resource changes to estimate costs.
hcl
terraform {
cloud {
organization = "your-org"
workspaces {
name = "your-workspace"
}
}
}
# No special resource or provider code needed for cost estimation
# Run terraform plan in CLI or trigger a plan in Terraform Cloud UI
terraform planExample
This example shows a simple Terraform configuration for an AWS EC2 instance. When you push this to Terraform Cloud with Cost Estimation enabled, the plan will include a cost estimate for the instance.
hcl
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
cloud {
organization = "example-org"
workspaces {
name = "example-workspace"
}
}
}
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
# Run terraform plan to see cost estimation in Terraform Cloud UIOutput
Plan: 1 to add, 0 to change, 0 to destroy.
Cost estimation report available in Terraform Cloud UI after plan completes.
Common Pitfalls
Common mistakes when using cost estimation in Terraform Cloud include:
- Not enabling Cost Estimation in the workspace settings, so no cost report is generated.
- Using unsupported resource types that do not have cost data, resulting in incomplete estimates.
- Expecting cost estimation to be 100% accurate; it is an estimate based on pricing data and may vary.
- Running plans locally without connecting to Terraform Cloud, which disables cost estimation.
terraform
### Wrong: Cost Estimation not enabled in workspace # No cost report will be generated ### Right: Enable Cost Estimation in Terraform Cloud workspace settings # Then run terraform plan in Terraform Cloud to get cost estimates
Quick Reference
Summary tips for using Terraform Cloud Cost Estimation:
- Enable Cost Estimation in your workspace settings under Settings > Cost Estimation.
- Run plans via Terraform Cloud UI or CLI connected to Terraform Cloud.
- Review the cost estimate report shown after the plan completes.
- Understand estimates are based on public pricing and may not include discounts or taxes.
- Use cost estimation to catch unexpected cost changes before applying infrastructure.
Key Takeaways
Enable Cost Estimation in Terraform Cloud workspace settings to activate cost reports.
Run terraform plans through Terraform Cloud to generate cost estimates automatically.
Cost estimation works by analyzing planned resource changes and matching pricing data.
Not all resource types have cost data, so estimates may be partial.
Use cost estimation to avoid surprises by reviewing costs before applying changes.