Terraform-Associate-004 practice question 5 of 35
Variables declared within a module are accessible outside of the module.
Full set: 360 questionsThe statement is false. Terraform modules are designed to be encapsulated, self-contained packages of configuration. Input variables are used to pass data into a module from a calling configuration. However, the variables, local values, and resources defined within a module are scoped locally to that module and are not directly accessible from the outside. To expose a value from a module to the parent (calling) module, an output value must be explicitly declared.
The "True" option is incorrect because it violates the fundamental principle of module encapsulation in Terraform. If internal variables were directly accessible, it would create tightly-coupled configurations, making modules less reusable, harder to maintain, and less predictable. The designated mechanism for returning data from a module is through output blocks, which act as a formal API for the module.
1. HashiCorp Terraform Documentation, "Input Variables": This source clarifies that input variables serve as parameters for a module, allowing a parent module to pass data into the child module. It does not describe a mechanism for accessing them from the outside. The documentation states, "Input variables serve as parameters for a Terraform module, allowing aspects of the module to be customized without altering the module's own source code, and allowing modules to be shared between different configurations." This defines their role as an input mechanism only.
Source: HashiCorp, "Terraform / Language / Modules / Input Variables".
2. HashiCorp Terraform Documentation, "Output Values": This is the most direct source refuting the statement. It explicitly defines output values as the sole method for exporting data from a module. The documentation states, "Output values are like the return values of a module... They are a way to expose some information about the resources a module creates to the module that called it." This confirms that a specific construct (output) is required to make data accessible outside the module.
Source: HashiCorp, "Terraform / Language / Modules / Output Values".
3. HashiCorp Terraform Documentation, "Module Composition": This section describes the benefits of modules, including encapsulation. It explains that modules are self-contained and interact with parent modules through a defined interface of input variables and output values. "A good module has a clean separation between its implementation details and its inputs and outputs. This makes the module easier to understand and to change over time." This principle of a "clean separation" is violated if internal variables are directly accessible.
Source: HashiCorp, "Terraform / Language / Modules / Module Composition".
Keep practicing
Take the free Terraform-Associate-004 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Terraform-Associate-004 practice questions
- Question 1You should run terraform fnt to rewrite all Terraform configurations within the current w…
- Question 2Module variable assignments are inherited from the parent module and you do not need to e…
- Question 3terraform validate confirms thesyntaxof Terraform files.
- Question 4Using the terraform state rm command against a resource will destroy it.
- Question 6terraform init retrieves and caches the configuration for all remote modules.
- Question 7terraform validate uses provider APIs to verify your infrastructure settings.
