terraci cost
Estimate monthly AWS costs by analyzing plan.json files in module directories.
Usage
bash
terraci cost [flags]Flags
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--module | -m | string | Estimate cost for a specific module | |
--output | -o | string | text | Output format: text, json |
How It Works
- Scans the working directory for
plan.jsonfiles (output ofterraform show -json plan.tfplan) - Detects the region from the module path using the configured
structure.pattern - Fetches AWS pricing data from the Bulk Pricing API (cached locally)
- Matches each resource to a cost definition and calculates monthly estimates
- Outputs per-module cost with before/after/diff
No AWS credentials required — pricing data is public.
Examples
bash
# Estimate all modules
terraci cost
# Single module
terraci cost --module platform/prod/eu-central-1/rds
# JSON output (for scripts/CI)
terraci cost --output json
# Verbose — shows per-resource breakdown and cache info
terraci cost -vOutput
Text (default)
platform
prod
eu-central-1
vpc monthly: $120.50 diff: +$64.80
aws_nat_gateway.main monthly: $32.40 az: eu-central-1a
aws_eip.nat monthly: $3.60
eks monthly: $450.00
aws_eks_cluster.main monthly: $73.00
summary
modules count: 3
total before: $570.50 after: $635.30 diff: +$64.80JSON
bash
terraci cost --output jsonjson
{
"modules": [
{
"module_id": "platform/prod/eu-central-1/rds",
"before_cost": 0,
"after_cost": 689.12,
"diff_cost": 689.12,
"resources": [
{
"address": "aws_db_instance.postgres",
"monthly_cost": 400.77,
"price_source": "aws-bulk-api"
},
{
"address": "aws_lambda_function.worker",
"monthly_cost": 12.04,
"price_source": "usage-based",
"status": "usage_estimated",
"status_detail": "usage-based estimate derived from provisioned concurrency"
},
{
"address": "aws_sqs_queue.jobs",
"monthly_cost": 0,
"price_source": "usage-based",
"status": "usage_unknown"
}
]
}
],
"total_before": 0,
"total_after": 762.12,
"total_diff": 762.12,
"currency": "USD"
}status is present for every resource result:
exactmeans TerraCi found a plan-time priceusage_estimatedmeans TerraCi derived a partial estimate from configured capacityusage_unknownmeans cost is still unknown at plan timeunsupported/failedmay also includefailure_kindandstatus_detail
Prerequisites
cost.enabled: truein.terraci.yamlplan.jsonfiles in module directories (generated byterraform show -json plan.tfplan)
Pricing Cache
AWS pricing data is cached locally to avoid repeated API calls:
- Default location:
~/.terraci/pricing(orcost.cache_dirin config) - Default TTL: 24 hours (or
cost.cache_ttl) - Cache status shown in output:
expires_in=23h49morstatus=expired
See Also
- Cost configuration — enable and configure cost estimation
- terraci summary — posts costs in MR/PR comments
- examples/cost-estimation — working example