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.
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)- A13% (7)
- B87% (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.
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.
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
Community Discussion
No community discussion yet for this question.