get_path_from_repo_root
unitstack
Usage
get_path_from_repo_root() --> stringget_path_from_repo_root returns the unit’s directory relative to the root of the Git repository, e.g. prod/mysql. In an included file, it returns the path of the unit that includes the file. It fails when the unit or stack file is not in a Git repository.
A file that many units include can use it to give each unit its own state key:
remote_state { backend = "s3" generate = { path = "backend.tf" if_exists = "overwrite_terragrunt" } config = { bucket = "my-tofu-state" key = "${get_path_from_repo_root()}/tofu.tfstate" region = "us-east-1" }}- root.hcl
Directoryprod
Directorymysql
- terragrunt.hcl
The key is prod/mysql/tofu.tfstate for prod/mysql.
Examples
locals { unit_path = get_path_from_repo_root() # "prod/mysql"}