locals block defines named computed values that can be referenced by resources and outputs within the same stack. Locals are the right place for conditional expressions and other transformations that cannot appear directly in resource properties.
Syntax
Example
Referencing locals
Locals fields are accessed via thelocals.fieldName qualified form:
locals.blockName.fieldName:
Why locals exist
Resource properties cannot containmatch or ternary (if/else) expressions directly — those must go in locals:
Supported expressions
Locals can hold any expression:- Ternary:
"a" if cond else "b" - Match:
match input.env { "prod": "t3.large" default: "t3.micro" } - F-strings:
f"prefix-{input.name}-suffix" - Arithmetic:
input.count * 2 - Boolean logic:
input.enabled && !input.disabled - Cross-stack refs:
@otherStack.someOutput
Reserved field names
The same reserved names that apply toinput also apply to locals:
stack, input, output, locals, module, provider, import, space, root, for, when, match, default, count, each
Duplicate field names
Locals field names are unique across alllocals blocks in the stack. Duplicates produce a compile error.
