TA-002-P · Question #100
You have declared an input variable called environment in your parent module. What must you do to pass the value to a child module in the configuration?
The correct answer is C. Declare a node_count input variable for child module. To pass a value from a parent module to a child module, the child module must first declare an input variable to receive that value.
Question
You have declared an input variable called environment in your parent module. What must you do to pass the value to a child module in the configuration?
Options
- AAdd node_count = var.node_count
- BDeclare the variable in a terraform.tfvars file
- CDeclare a node_count input variable for child module
- DNothing, child modules inherit variables of parent module
How the community answered
(28 responses)- B7% (2)
- C89% (25)
- D4% (1)
Why each option
To pass a value from a parent module to a child module, the child module must first declare an input variable to receive that value.
`node_count = var.node_count` is the syntax used in the parent module's `module` block to pass a value, but the prerequisite is that the child module must first declare an input variable to receive it.
Declaring a variable in a `terraform.tfvars` file provides a value to variables in the root module, but it does not directly pass values to child modules.
Child modules operate in an isolated scope and do not automatically inherit variables from their parent modules. For a parent module to pass a value to a child, the child module must explicitly declare an input variable to accept that value.
Child modules do not inherit variables from parent modules; variables must be explicitly defined and passed between modules.
Concept tested: Module input variables
Source: https://developer.hashicorp.com/terraform/language/modules/syntax#input-variables
Topics
Community Discussion
No community discussion yet for this question.