Context-based Variables
Terramate Lets Variables represent context-based variables that can be used to compute local blocks available in the current code generation block only to not pollute the global namespace with temporary or intermediate variables.
Available contexts are:
- within
generate_hcl
blocks - within
generate_file
blocks
They are defined the same way as Global Variables and support similar features.
hcl
lets {
<variable-name> = <expression>
}
The following key differences exist compared to Terramate Globals:
- they are only available in some defined context e.g.,
generate_hcl
andgenerate_file
- they do not support labels
- they support the additional
let
namespace in expressions
Example:
hcl
generate_file "file.json" {
lets {
# let.json is available in the current generate_file block only
json = tm_jsonencode({ "hello" = "world" })
}
content = let.json
}