Skip to main content
In this lesson, we’ll dive into Terragrunt’s path_relative_to_include function. This built-in helper calculates the relative path between the current .hcl file and the file specified in its include block. Use it to:
  • Organize and modularize your configuration files
  • Construct dynamic file paths
  • Segregate remote state keys per module

Why Use path_relative_to_include?

When used without arguments, path_relative_to_include() returns the relative path from the current folder to where common.hcl (or your included file) lives.

Typical Terragrunt Setup

Imagine you have a shared common.hcl in a parent directory and multiple child modules that include it. You can tag each module’s remote state with its relative path:
Here’s what happens when you run terragrunt plan:
Notice how the Path tag reflects this module’s folder relative to common.hcl. By doing so, each module’s Terraform state is stored under a unique key in your remote backend, enhancing clarity and maintainability.

Further Reading

Watch Video