TA-002-P · Question #251
John is writing a module and within the module, there are multiple places where he has to use the same conditional expression but he wants to avoid repeating the same values or expressions multiple…
The correct answer is A. Local Values. Local Values (defined in a locals {} block) allow you to assign a name to an expression and reuse it throughout the module without repetition. This is ideal for complex or repeated conditional expressions. Unlike variables (which are inputs from outside the module) or outputs…
Question
John is writing a module and within the module, there are multiple places where he has to use the same conditional expression but he wants to avoid repeating the same values or expressions multiple times in a configuration,. What is a better approach to dealing with this?
Options
- ALocal Values
- BExpressions
- CFunctions
- DVariables
How the community answered
(48 responses)- A71% (34)
- B19% (9)
- C6% (3)
- D4% (2)
Explanation
Local Values (defined in a locals {} block) allow you to assign a name to an expression and reuse it throughout the module without repetition. This is ideal for complex or repeated conditional expressions. Unlike variables (which are inputs from outside the module) or outputs, locals are scoped to the module and computed internally. This keeps code DRY (Don't Repeat Yourself) and easier to maintain - changing the expression in one place updates it everywhere it is referenced.
Topics
Community Discussion
No community discussion yet for this question.