Skip to main content

Terragrunt

The infracost scan command automatically detects Terragrunt projects, though we generally recommend setting up a config file for Terragrunt repos.

infracost scan path/to/terragrunt/repo

To exclude directories or modules, list them in exclude_paths on the relevant project in your infracost.yml:

version: "0.3"
projects:
- path: .
exclude_paths:
- dev
- test

Usage file

If your Terragrunt project has multiple modules and you want to specify different usage files for each module, you will need to add each Terragrunt subdirectory and usage file to the Infracost config file, see an example here.

If you have any feedback about how we should support multiple usage files with Terragrunt in the future, please comment on or follow this issue.

Source map

The INFRACOST_TERRAFORM_SOURCE_MAP environment variable is useful when you want to replace module URLs used by Infracost (e.g. replace private URLs with public ones). See this docs section for more details.

How the Terragrunt integration works

When infracost scan runs against a directory:

  1. Infracost detects a Terragrunt project by checking for a Terragrunt config file in the specified path, which will be terragrunt.hcl, terragrunt.hcl.json or the value of the TERRAGRUNT_CONFIG environment variable. If Infracost does not detect your project as a Terragrunt project, make sure this file exists in the specified path or in any of the subdirectories with a depth less than 5.

  2. If Terragrunt is detected, Infracost downloads any required source files to an .infracost cache, detects Terragrunt defined inputs, then parses HCL directly.

  3. Infracost reports a cost breakdown for each Terragrunt module, which you can then drill into with infracost inspect.