Skip to content

find_in_parent_folders

unitstack

Usage

find_in_parent_folders(name: string, [fallback: string]) --> string

A unit uses find_in_parent_folders to find the file it includes:

prod/mysql/terragrunt.hcl
include "root" {
path = find_in_parent_folders("root.hcl")
}
  • root.hcl
  • Directoryprod
    • Directorymysql
      • terragrunt.hcl

The search starts in the folder above the unit or stack file and moves up until it finds name.

In an included file

The search starts from the unit that includes the file. Here, root.hcl finds prod/env.hcl when prod/mysql includes it:

root.hcl
locals {
env = read_terragrunt_config(find_in_parent_folders("env.hcl"))
}
  • root.hcl
  • Directoryprod
    • env.hcl
    • Directorymysql
      • terragrunt.hcl

Parameters

fallbackoptional(string)

The value to return, as given, when no folder above has name. Without it, the function fails.

Examples

Falls back to a default file when no folder above the unit has region.hcl.

prod/mysql/terragrunt.hcl
locals {
default = "${get_repo_root()}/defaults/region.hcl"
region_file = find_in_parent_folders("region.hcl", local.default)
}