terragruntterraformci-cdcost-estimation

Terragrunt cost estimation: pricing a whole stack before apply

Terragrunt's module composition breaks naive cost tools. Here's how to estimate a Terragrunt stack by resolving its dependency graph, run it in CI, and gate PRs on a budget — no apply required.

The C3X Team··6 min read

Quick answer

C3X estimates cloud cost for Terragrunt-managed infrastructure by resolving the module composition and dependency graph the way Terragrunt does, then pricing the resulting resources against a live pricing catalog — no apply required. Run it locally or in CI, and gate PRs with a budget policy the same way you would for plain Terraform.

Terragrunt keeps large Terraform estates DRY — shared config, generated backends, dependency-aware run-all across dozens of modules. That structure is exactly what makes naive cost estimation fall over: tools that read one module's HCL miss the composed reality. Estimating a Terragrunt stack properly means resolving the same module graph Terragrunt resolves.

Why Terragrunt needs more than an HCL parser

A Terragrunt unit pulls in a source module, injects inputs, generates a backend, and may depend on outputs from sibling units. The cost of the stack is the sum of all those resolved units, not any single directory's files. To price it accurately you have to evaluate the composition — which module, which inputs, how many times — across the whole tree.

Estimating a Terragrunt stack with C3X

# Estimate a Terragrunt directory (resolves the stack)
c3x estimate --path ./infra/live/prod

# Or feed a generated plan for maximum fidelity
terragrunt run-all plan -out=tfplan
c3x estimate --plan tfplan

C3X resolves the resources across the units and prices them from a live catalog, producing one aggregated monthly estimate for the stack. The figures match the per-resource catalog pages, so you can drill into any line item.

Gate Terragrunt PRs on cost

The real value is catching expensive changes before merge. Run C3X in CI against the Terragrunt stack and apply a budget policy that fails the build when the estimate exceeds a threshold — the same guardrail covered in budget guardrails in CI. A PR that adds a new managed database or scales a node pool shows its cost delta in the pipeline instead of on next month's invoice.

Where it fits

This is the Terragrunt-specific version of estimating Terraform costs before deploy. If you've standardized on Terragrunt for multi-environment, multi-account estates, cost estimation should understand that structure rather than force you to estimate module by module.

FAQ

Can you estimate cloud costs for Terragrunt-managed infrastructure?

Yes. C3X understands Terragrunt's structure — it resolves the generated Terraform across your stack's modules and dependency graph and prices the resulting resources, so you get a cost estimate for a Terragrunt project the same way you would for plain Terraform, without first running an apply.

Why is Terragrunt cost estimation harder than plain Terraform?

Terragrunt layers DRY configuration, remote-state generation, and run-all across many modules with dependencies between them. A naive parser sees only one module's HCL. Estimating the true cost means resolving the same module composition Terragrunt would, so the estimate reflects the whole stack, not a single unit.

Do I need to run terragrunt apply to estimate cost?

No. The point of pre-deployment estimation is to see the cost before anything is provisioned. C3X reads the configuration (or a generated plan) and prices it statically, so you get the number in CI or locally without touching real infrastructure.

Does C3X work with terragrunt run-all?

It's built for multi-module stacks. Point C3X at the Terragrunt directory and it prices the resources across the units, so a run-all-style deployment of many modules produces one aggregated cost estimate rather than forcing you to estimate each module separately.

Can I gate Terragrunt PRs on cost in CI?

Yes. Run C3X in your pipeline against the Terragrunt stack and apply a budget policy that fails the build (or comments on the PR) when the estimated monthly cost exceeds a threshold — the same guardrail pattern that works for plain Terraform.

How accurate is the estimate?

C3X prices resources from a live cloud pricing catalog, and figures match its per-resource catalog pages. Usage-driven costs (data transfer, requests) need a usage file to be included; fixed resource costs (instances, databases, storage) are estimated directly from your configuration.

What to do next

Point C3X at your Terragrunt live directory and get a stack-wide estimate in one run. The quickstart walks through installation and your first estimate, and the CI/CD guide shows how to wire the budget gate into your pipeline.

Try C3X on your own Terraform

Free and open source. No API key required. One command to install, one command to estimate.