nerdexam
HashiCorp

TA-002-P · Question #101

If a module declares a variable with a default, that variable must also be defined within the module.

The correct answer is B. False. A module variable declared with a default value does not require an external definition, as Terraform uses the specified default if no other value is provided.

Interact with Terraform modules

Question

If a module declares a variable with a default, that variable must also be defined within the module.

Options

  • ATrue
  • BFalse

How the community answered

(52 responses)
  • A
    13% (7)
  • B
    87% (45)

Why each option

A module variable declared with a default value does not require an external definition, as Terraform uses the specified default if no other value is provided.

ATrue

The statement is false because the presence of a `default` value means the variable is already 'defined' in terms of having a fallback value, removing the requirement for an external definition.

BFalseCorrect

If a module declares a variable with a `default` value, Terraform will use that value if no other value is explicitly provided from a `.tfvars` file, environment variable, or command-line argument. Thus, it does not strictly need to be 'defined' externally.

Concept tested: Module variable default values

Source: https://developer.hashicorp.com/terraform/language/values/variables#default-values

Topics

#Terraform variables#Module variables#Default values#Variable definition

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice