Core Terragrunt Functions
| Function | Description |
|---|---|
read_terragrunt_config | Read and parse another Terragrunt configuration file, giving you access to its inputs, dependencies, and locals. |
find_in_parent_folders | Recursively search parent directories to locate specific files (e.g., terragrunt.hcl), enabling shared configs. |
path_relative_to_include | Compute the relative path from the current file to an included configuration, promoting modular directory layouts. |
get_terragrunt_dir | Return the full path of the directory containing the current terragrunt.hcl file, useful for dynamic file references. |
get_parent_terragrunt_dir | Retrieve the directory path of the parent Terragrunt configuration, supporting hierarchical inheritance. |
run_cmd | Execute a shell command directly within Terragrunt, allowing automation of external tools or scripts. |
Use
run_cmd with caution. Executing shell commands can expose sensitive information or introduce security risks. Always validate inputs and avoid hardcoding credentials.
Combining Terragrunt with Terraform Functions
Terragrunt functions become even more powerful when combined with Terraform’s native functions. For example, to extract just the directory name of your current Terragrunt configuration, you can use Terraform’sbasename together with get_terragrunt_dir:
Links and References
- Terragrunt Documentation: https://terragrunt.gruntwork.io/docs/
- Terraform Language Functions: https://developer.hashicorp.com/terraform/language/functions
- Terragrunt GitHub Repository: https://github.com/gruntwork-io/terragrunt
- Best Practices for Infrastructure as Code: https://www.hashicorp.com/resources/series/infrastructure-as-code-guide