Skip to content

get_path_to_repo_root

unitstack

Usage

get_path_to_repo_root() --> string

get_path_to_repo_root returns the relative path from the unit’s directory up to the root of the Git repository, e.g. ../.. for prod/vpc. In an included file, the path still starts at the unit’s directory. It fails when the unit or stack file is not in a Git repository.

Use it to point a relative source at a module in the same repository:

prod/vpc/terragrunt.hcl
terraform {
source = "${get_path_to_repo_root()}//modules/vpc"
}
  • Directorymodules
    • Directoryvpc
      • main.tf
  • Directoryprod
    • Directoryvpc
      • terragrunt.hcl

The source is ../..//modules/vpc.

Examples

prod/mysql/terragrunt.hcl
locals {
repo_root = get_path_to_repo_root() # "../.."
}