Skip to content

read_tfvars_file

unitstack

Usage

read_tfvars_file(file_path: string) --> string

read_tfvars_file returns a JSON string, so decode it with jsondecode to use the variables:

terragrunt.hcl
locals {
common = jsondecode(read_tfvars_file("common.tfvars"))
}
inputs = merge(local.common, {
instance_type = "t3.micro"
})

It fails when the file doesn’t exist. Terragrunt records the file as read, so --queue-include-units-reading and reading= filters find the unit.

Parameters

file_pathstring

The file to read. A relative path resolves from the unit’s directory, even in an included file. A path ending in json is read as JSON, any other as a .tfvars file.

Examples

prod/app/terragrunt.hcl
locals {
tfvars = read_tfvars_file("common.tfvars")
# "{\"region\":\"us-east-1\"}"
}