Skip to content

path_relative_from_include

unitstack

Usage

path_relative_from_include([name: string]) --> string

path_relative_from_include is the reverse of path_relative_to_include. Together, they let an included file build a relative path for each unit, e.g. a source in a sibling folder:

terragrunt/root.hcl
locals {
to_root = path_relative_from_include()
to_unit = path_relative_to_include()
}
terraform {
source = "${local.to_root}/../sources//${local.to_unit}"
}
  • Directorysources
    • Directorymysql
      • main.tf
    • Directorysecrets
      • Directorymysql
        • main.tf
  • Directoryterragrunt
    • root.hcl
    • Directorymysql
      • terragrunt.hcl
    • Directorysecrets
      • Directorymysql
        • terragrunt.hcl

The source is ../../sources//mysql for terragrunt/mysql and ../../../sources//secrets/mysql for terragrunt/secrets/mysql. Without an include block, the function returns ..

For an absolute path to the included file’s directory, use get_parent_terragrunt_dir.

Parameters

nameoptional(string)

The label of the include block to measure to. A unit with more than one include block needs it. In the included file, it has no effect.

Examples

When prod/mysql/terragrunt.hcl includes this file.

root.hcl
locals {
root_path = path_relative_from_include() # "../.."
}