Skip to content

get_terragrunt_dir

unitstack

Usage

get_terragrunt_dir() --> string

get_terragrunt_dir returns the absolute path of the directory of the unit or stack file, e.g. /home/me/infra/prod/mysql. In an included file, it returns the directory of the unit that includes it. For the included file’s own directory, use get_parent_terragrunt_dir. In a file read with read_terragrunt_config, it returns that file’s directory. To get the unit’s directory there, use get_original_terragrunt_dir.

In a unit, Terragrunt runs OpenTofu/Terraform in a copy of the module under .terragrunt-cache, so a relative path in an argument resolves from there. Start the path with get_terragrunt_dir to resolve it from the unit’s directory:

frontend-app/terragrunt.hcl
terraform {
source = "git::https://github.com/acme/modules.git//app?ref=v1.0.0"
extra_arguments "common_vars" {
commands = ["plan", "apply"]
arguments = [
"-var-file=${get_terragrunt_dir()}/../common.tfvars",
]
}
}
  • common.tfvars
  • Directoryfrontend-app
    • terragrunt.hcl

Examples

In a repository checked out at /home/me/infra.

prod/mysql/terragrunt.hcl
locals {
unit_dir = get_terragrunt_dir() # "/home/me/infra/prod/mysql"
}