get_path_to_repo_root
unitstack
Usage
get_path_to_repo_root() --> stringget_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:
terraform { source = "${get_path_to_repo_root()}//modules/vpc"}Directorymodules
Directoryvpc
- main.tf
Directoryprod
Directoryvpc
- terragrunt.hcl
The source is ../..//modules/vpc.
Examples
locals { repo_root = get_path_to_repo_root() # "../.."}