Modules do not inherit variables from the parent module. All modules are self-contained units. So you have to explicitly define variables in the child module, and then explicit set these variables in the parent module, when you instantiate the child module.
A module in Terraform can only access variables that are explicitly passed as input variables or declared as outputs by the parent module. It cannot access variables declared within the parent module unless they are passed to the module as input variables. This is known as the "principle of least privilege," which means that modules should only have access to the information and resources that they need to perform their tasks, and no more.
So, to refer to a variable from a parent module, you must either pass it as an input variable to the child module or declare it as an output variable in the parent module and then reference it in the child module using the module.<name>.<output> syntax.
Answer: B
A child module can refer to variables declared in its parent module, but it does so in a controlled and explicit manner. By default, child modules do not have automatic access to all variables in the parent module. To reference a variable from the parent module in a child module, you should declare an input variable with the same name in the child module and then explicitly pass the value from the parent module.
The question is whether a (child) module can always refer to ALL variables in the parent module. The answer is NO. The child module can "see" and refer to the variables defined in its own (child module's) definition. The child module has no visibility of the variables defined in the parent module. Thus it cannot refer to them. Answer is False (B)
A module can refer to variables in its parent module only if those variables are explicitly passed to it as input variables. If a variable is not passed to a child module, then that child module cannot refer to it. So the correct answer is B - False.
No, a module cannot always refer to all variables declared in its parent module. Only variables declared as public in the parent module can be referred to by a module.
False.
A module can refer to variables in its parent module only if they are explicitly passed to it using variable definitions or module blocks in the calling module.
B. False
A module can only refer to variables that are explicitly passed to it as inputs, either through variable declarations or module calls. It cannot automatically refer to all variables declared in its parent module, as it may not need or have access to all of them. If a variable is not passed to a module as an input, the module will not be able to use it directly.
B you must declare the variable in the child module if you can use it. Also, the parent module must call the child module using inputs. First, the parent module declares variables, second, the child module declares its inputs, then, the parent module call to the child module using inputs that were declared in the variables.tf of the child module.
A. True. A module in Terraform can always refer to all variables declared in its parent module, as long as the parent module is called before the child module in the configuration file.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Burakko
Highly Voted 2 years, 2 months agoBurakko
2 years, 2 months agokiran15789
Highly Voted 1 year, 6 months agoTyler2023
1 year agoTyler2023
1 year agoDemonik
Most Recent 12 months agoStargazer11
1 year agomilan92stankovic
1 year, 5 months agoNi33
1 year, 6 months agoraf314
1 year, 7 months agoBennaniHaythem
1 year, 7 months agosylvergorilla
1 year, 7 months agoSathisgm
1 year, 7 months agocamps
1 year, 7 months agoNunyabiznes
1 year, 8 months agophidelics
1 year, 8 months agorotimislaw
1 year, 9 months agoagmesas
1 year, 9 months agoZeppoonstream
1 year, 10 months agossanjayt
1 year, 10 months ago