Domain 5 of 8 · Chapter 2 of 4

Variable scope within modules

Unlock the complete study guide + 1,040 practice questions across 16 full exams.

Bundled into the existing HashiCorp Certified: Terraform Associate premium course — no separate purchase.

14-day money-back guarantee — no questions asked.

Included in this chapter:

  • The module boundary: two channels
  • Passing inputs down into a child
  • Reading results back up with outputs
  • Providers: the exception to isolation
  • Exam-pattern recognition

The three channels across a module boundary

AspectInput variablesOutput valuesProvider configurations
Direction of flowCaller into childChild back to callerCaller into child
How it is referencedvar.NAME inside the childmodule.LABEL.OUTPUT in the callerprovider address, e.g. aws or aws.usw2
Crosses automatically?No; passed as a module argumentNo; must be declared as an outputDefault: yes (inherited); aliased: no
Declared in the child byvariable blockoutput blockrequired_providers plus configuration_aliases

Cheat sheet

  • Child modules receive only explicitly passed inputs
  • Each module declares its own variables locally
  • Modules cannot reach into another module's variables
  • Parents read only explicitly declared child outputs
  • Output reference syntax is module.
  • Default provider configurations are inherited by child modules
  • Aliased providers must be passed explicitly
  • Reusable modules should not define provider blocks

Unlock with Premium — includes all practice exams and the complete study guide.

References

  1. Creating Modules
  2. Input Variables
  3. Output Values
  4. Module Blocks
  5. Providers Within Modules