0
0
Terraformcloud~10 mins

Outputs for module communication in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Outputs for module communication
Define output in child module
Apply child module
Output value stored
Parent module calls child module
Parent accesses output via module.<name>.<output>
Use output in parent resources or variables
Outputs in Terraform modules let child modules share values with parent modules, enabling communication and reuse.
Execution Sample
Terraform
module "child" {
  source = "./child"
}

output "child_value" {
  value = module.child.example_output
}
Parent module calls child module and accesses its output named example_output.
Process Table
StepActionEvaluationResult
1Child module defines output 'example_output'Set output value to 'Hello from child'Output stored in child module state
2Parent module calls child moduleChild module initialized and appliedChild module resources created
3Parent accesses module.child.example_outputRetrieve output value'Hello from child' returned
4Parent uses output in its own output 'child_value'Assign value'child_value' output set to 'Hello from child'
5Terraform apply completesOutputs availableParent output 'child_value' shows 'Hello from child'
💡 All outputs resolved and available for parent module use after apply
Status Tracker
VariableStartAfter Step 1After Step 3Final
example_outputundefined'Hello from child''Hello from child''Hello from child'
child_valueundefinedundefinedundefined'Hello from child'
Key Moments - 2 Insights
Why can't the parent module access child module variables directly?
The parent module accesses values only through outputs defined in the child module, as shown in step 3 of the execution_table.
What happens if the child module does not define an output?
The parent module cannot retrieve any value from the child module, so referencing module.child.<output> will fail, as outputs must be explicitly declared (step 1).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of 'example_output' after step 1?
Aundefined
B'Hello from child'
Cnull
DError
💡 Hint
Check the 'Result' column in row for step 1 in execution_table
At which step does the parent module retrieve the child's output value?
AStep 3
BStep 2
CStep 4
DStep 5
💡 Hint
Look for 'Parent accesses module.child.example_output' in execution_table
If the child module output value changed, which step would reflect the new value?
AStep 4
BStep 3
CStep 1
DStep 5
💡 Hint
Output value is set in child module definition at step 1
Concept Snapshot
Terraform module outputs:
- Defined in child module with 'output' block
- Provide values to parent module
- Accessed via module.<name>.<output>
- Enable communication between modules
- Must be declared explicitly to be accessible
Full Transcript
In Terraform, outputs allow a child module to share values with its parent module. The child module defines outputs using the output block. When the parent module calls the child module, it can access these outputs using the syntax module.<child_name>.<output_name>. This process happens during terraform apply, where the child module runs, sets its outputs, and the parent module retrieves them. Outputs enable modules to communicate and reuse values safely and clearly.