0
0
Terraformcloud~10 mins

Module outputs in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Module outputs
Define output in module
Run terraform apply
Terraform processes module
Module generates output value
Output value available to root module
Use output in root module or display
This flow shows how a Terraform module defines outputs, which are then produced during apply and made available to the root module or user.
Execution Sample
Terraform
module "example" {
  source = "./example_module"
}

output "instance_ip" {
  value = module.example.instance_ip
}
This code calls a module and outputs the instance IP address that the module provides.
Process Table
StepActionEvaluationResult
1Terraform reads root moduleFinds module blockPrepares to call example_module
2Terraform enters example_moduleProcesses resourcesCreates instance with IP 10.0.0.5
3Module output 'instance_ip' evaluatedReads instance IPValue is 10.0.0.5
4Terraform returns output to rootAssigns module.example.instance_ipValue 10.0.0.5 available
5Root module output 'instance_ip' evaluatedReads module outputOutputs 10.0.0.5 to user
6Terraform apply completesOutputs displayedinstance_ip = 10.0.0.5
💡 Terraform apply finishes after outputs are displayed to the user.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
module.example.instance_ipundefinedundefined10.0.0.510.0.0.510.0.0.5
output.instance_ipundefinedundefinedundefinedundefined10.0.0.5
Key Moments - 2 Insights
Why does the output value only appear after terraform apply?
Because the module resources must be created first to have real values; see execution_table step 2 and 3 where the instance IP is assigned during apply.
Can outputs from a module be used inside the same module?
No, outputs are only available to the root or calling module after apply, not inside the module itself; outputs are for passing data out.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of module.example.instance_ip after step 3?
A10.0.0.5
Bnull
Cundefined
Dmodule output not yet evaluated
💡 Hint
Check the 'Result' column at step 3 in the execution_table.
At which step does the root module output 'instance_ip' become available to the user?
AStep 4
BStep 5
CStep 2
DStep 6
💡 Hint
Look for when the root module output is evaluated in the execution_table.
If the module did not define an output, what would happen to the root module output referencing it?
AIt would show null
BIt would show an empty string
CTerraform would error during apply
DIt would show the resource ID
💡 Hint
Outputs must be defined in the module to be accessible; see key_moments about output availability.
Concept Snapshot
Terraform module outputs:
- Defined inside modules with 'output' blocks
- Provide values from module to root module
- Available only after 'terraform apply'
- Used to share info like IPs, IDs
- Cannot be used inside the same module
- Accessed as module.<name>.<output>
Full Transcript
This visual execution shows how Terraform module outputs work. First, Terraform reads the root module and finds a module block. It then processes the module's resources, creating infrastructure like an instance with an IP address. The module defines an output that reads this IP. After creation, Terraform assigns this output value to the root module's reference. Finally, the root module outputs the value to the user after apply completes. Outputs are only available after resources exist and cannot be used inside the module itself. This flow helps pass information from modules back to the root or other modules.