Skip to content

terraci cost

Estimate monthly AWS costs by analyzing plan.json files in module directories.

Usage

bash
terraci cost [flags]

Flags

FlagShortTypeDefaultDescription
--module-mstringEstimate cost for a specific module
--output-ostringtextOutput format: text, json

How It Works

  1. Scans the working directory for plan.json files (output of terraform show -json plan.tfplan)
  2. Detects the region from the module path using the configured structure.pattern
  3. Fetches AWS pricing data from the Bulk Pricing API (cached locally)
  4. Matches each resource to a cost definition and calculates monthly estimates
  5. 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 -v

Output

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.80

JSON

bash
terraci cost --output json
json
{
  "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:

  • exact means TerraCi found a plan-time price
  • usage_estimated means TerraCi derived a partial estimate from configured capacity
  • usage_unknown means cost is still unknown at plan time
  • unsupported / failed may also include failure_kind and status_detail

Prerequisites

  • cost.enabled: true in .terraci.yaml
  • plan.json files in module directories (generated by terraform show -json plan.tfplan)

Pricing Cache

AWS pricing data is cached locally to avoid repeated API calls:

  • Default location: ~/.terraci/pricing (or cost.cache_dir in config)
  • Default TTL: 24 hours (or cost.cache_ttl)
  • Cache status shown in output: expires_in=23h49m or status=expired

See Also

Released under the MIT License.