Cost Estimation
TerraCi can estimate the monthly cost impact of infrastructure changes by analyzing Terraform plans against AWS pricing data. Cost estimates are calculated per module and displayed alongside plan results in MR comments.
Basic Configuration
plugins:
cost:
cache_dir: "~/.terraci/pricing"
cache_ttl: "24h"
providers:
aws:
enabled: trueConfiguration Options
providers.aws.enabled
Enable AWS cost estimation.
plugins:
cost:
providers:
aws:
enabled: truecache_dir
Directory to cache AWS pricing data fetched from the Bulk Pricing API. Caching avoids repeated API calls and speeds up subsequent runs.
plugins:
cost:
cache_dir: ~/.terraci/pricing # defaultcache_ttl
How long cached pricing data remains valid before being re-fetched.
plugins:
cost:
cache_ttl: "24h" # defaultAccepts Go duration strings: "1h", "30m", "72h", etc.
How It Works
- After
terraform plancompletes, TerraCi reads theplan.jsonfile from each module directory. - Resource changes are extracted and matched against registered AWS resource definitions.
- Pricing is fetched from the AWS Bulk Pricing API and cached locally according to
cache_ttl. - Per-resource hourly and monthly costs are calculated for both the before and after states.
- Results are aggregated into a per-module cost summary with before/after/diff values.
Cost estimation requires plan.json (produced by terraform show -json) to be present in module directories. This is generated automatically when plan_enabled: true in the pipeline configuration (GitLab or GitHub).
Supported AWS Resources
| Category | Resources |
|---|---|
| EC2 | Instances, EBS volumes, Elastic IPs, NAT Gateways |
| RDS | Instances, clusters, cluster instances |
| ELB | Application Load Balancers, Classic Load Balancers |
| ElastiCache | Clusters, replication groups, serverless caches |
| EKS | Clusters, node groups |
| Serverless | Lambda, DynamoDB, SQS, SNS |
| Storage | S3, CloudWatch alarms/log groups, KMS keys, Route 53 zones, Secrets Manager |
Each resource type has a dedicated definition that maps Terraform resource attributes to the corresponding pricing dimensions.
MR/PR Integration
When cost estimation is enabled, cost estimates appear in the MR/PR comment table. Each module shows its monthly cost difference:
### 💰 Cost Estimation
| Module | Monthly Before | Monthly After | Diff |
|--------|---------------|---------------|------|
| platform/prod/eu-central-1/vpc | $120.50 | $185.30 | +$64.80 |
| platform/prod/eu-central-1/eks | $450.00 | $450.00 | $0.00 |
| **Total** | **$570.50** | **$635.30** | **+$64.80** |Full Example
plugins:
cost:
cache_dir: ~/.terraci/pricing
cache_ttl: "24h"
providers:
aws:
enabled: true
# Works with either provider:
gitlab:
plan_enabled: true
mr:
comment:
enabled: true
# Or with GitHub:
# github:
# plan_enabled: true
# pr:
# comment:
# enabled: trueThis configuration enables cost estimation with default caching, and displays the results in MR/PR comments alongside plan output.
CLI Command
Run cost estimation directly from the command line:
# Estimate all modules with plan.json
terraci cost
# Estimate a single module
terraci cost --module platform/prod/eu-central-1/rds
# JSON output
terraci cost --output json
# Verbose — shows per-resource breakdown and pricing cache info
terraci cost -vThe terraci cost command scans for plan.json files, fetches pricing data, and outputs per-module cost estimates. Pricing cache location and TTL expiration are shown in the output.
In JSON output, each resource now carries a status:
exactfor fully priced resourcesusage_estimatedwhen TerraCi can derive a partial estimate from configured capacityusage_unknownwhen the resource still needs runtime usage dataunsupported/failedwith optionalfailure_kindandstatus_detail
Note:
terraci costrequiresplugins.cost.providers.aws.enabled: truein your.terraci.yaml.
In CI pipelines, cost estimation runs automatically as part of the terraci summary command (which posts MR/PR comments). Use terraci cost for local development and ad-hoc cost checks.
Examples
See examples/cost-estimation for a working example with VPC, EKS, and RDS modules.
See Also
- Merge Request Integration — MR comments with plan summaries and cost estimates
- Pipeline Generation Guide — end-to-end guide for generating CI pipelines