Skip to content

get_parent_terragrunt_dir

unitstack

Usage

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

A file that many units include can use get_parent_terragrunt_dir to point every unit at a file next to it, however deep the unit is:

root.hcl
terraform {
extra_arguments "common_vars" {
commands = ["plan", "apply"]
arguments = [
"-var-file=${get_parent_terragrunt_dir()}/common.tfvars",
]
}
}
  • root.hcl
  • common.tfvars
  • Directoryapp1
    • terragrunt.hcl
  • Directorytests
    • Directoryapp2
      • terragrunt.hcl

Without an include block, it returns the unit’s directory, like get_terragrunt_dir.

A unit with more than one include block passes the label of the one to use:

prod/mysql/terragrunt.hcl
include "root" {
path = find_in_parent_folders("root.hcl")
}
include "region" {
path = find_in_parent_folders("region.hcl")
}
terraform {
source = "${get_parent_terragrunt_dir("root")}/modules//mysql"
}

Parameters

nameoptional(string)

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

Examples

When /home/me/infra/prod/mysql/terragrunt.hcl includes this file.

root.hcl
locals {
root_dir = get_parent_terragrunt_dir() # "/home/me/infra"
}