nerdexam
HashiCorp

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…

Read, generate, and modify configuration

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)
  • A
    71% (34)
  • B
    19% (9)
  • C
    6% (3)
  • D
    4% (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

#Local Values#Configuration Reuse#DRY Principle#Module Development

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice