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:
-
Infracost detects a Terragrunt project by checking for a Terragrunt config file in the specified path, which will be
terragrunt.hcl,terragrunt.hcl.jsonor the value of theTERRAGRUNT_CONFIGenvironment 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. -
If Terragrunt is detected, Infracost downloads any required source files to an
.infracostcache, detects Terragrunt defined inputs, then parses HCL directly. -
Infracost reports a cost breakdown for each Terragrunt module, which you can then drill into with
infracost inspect.