Functions
Terragrunt allows you to use built-in functions anywhere in terragrunt.hcl, just like OpenTofu/Terraform!
OpenTofu/Terraform built-in functions
Section titled “OpenTofu/Terraform built-in functions”All OpenTofu built-in functions through OpenTofu 1.13 are supported in Terragrunt config files:
terraform { source = "../modules/${basename(get_terragrunt_dir())}"}
inputs = { name = trimspace(" my-app ") environment = join("-", ["prod", "eu"]) state_path = format("%s/tofu.tfstate", path_relative_to_include())}Note: Any file* functions (file, fileexists, filebase64, etc.) are relative to the directory containing the terragrunt.hcl file they’re used in.
Given the following structure:
Directoryterragrunt
- common.tfvars
Directoryassets
Directorymysql
- assets.txt
- terragrunt.hcl
Then assets.txt could be read with the following function call:
file("assets/mysql/assets.txt")Note:
These functions are internal to the OpenTofu codebase, so Terragrunt keeps its own copy of their implementations and follows OpenTofu releases.
Terragrunt provides functions of its own for problems specific to Terragrunt, e.g. executing arbitrary shell commands with run_cmd in whatever language you like.
If there is a specific function you would like to see supported directly in Terragrunt, please open an issue requesting it. Make sure to include the use case you have in mind so we can understand the problem you are trying to solve, and why existing Terragrunt functions are not sufficient.