0
0
Terraformcloud~10 mins

Terraform output command - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Terraform output command
Run 'terraform apply'
Resources created
Outputs defined in config
Run 'terraform output'
Terraform reads state file
Outputs values displayed
User sees output values
Terraform creates resources, stores their info, then 'terraform output' reads and shows these stored output values.
Execution Sample
Terraform
output "instance_ip" {
  value = aws_instance.web.public_ip
}

# After apply
terraform output instance_ip
Defines an output for instance IP, then shows how to get its value after applying.
Process Table
StepCommandActionState ReadOutput Displayed
1terraform applyCreate resources and save stateN/AN/A
2terraform outputRead state file for outputsReads all output valuesDisplays all output values
3terraform output instance_ipRead specific outputReads instance_ip valueDisplays instance_ip value
4terraform output unknownRead non-existent outputNo such output in stateError: output not found
5terraform output -jsonRead all outputs in JSONReads all outputsDisplays all outputs in JSON
💡 Outputs displayed or error shown if output not found.
Status Tracker
VariableBefore ApplyAfter ApplyAfter Output Command
aws_instance.web.public_ipundefined54.12.34.5654.12.34.56
output instance_ipundefineddefined in config54.12.34.56
Key Moments - 3 Insights
Why does 'terraform output' show an error for an unknown output name?
Because the output name is not defined in the Terraform config or state, as shown in execution_table step 4.
Does 'terraform output' create or change resources?
'terraform output' only reads existing state and shows output values; it does not create or modify resources (see step 2).
What does the '-json' flag do with 'terraform output'?
It shows all outputs in JSON format, useful for automation, as shown in step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what output does 'terraform output instance_ip' display at step 3?
ANo output, just a blank line
BAn error message about missing output
CThe public IP address of the instance
DThe entire state file content
💡 Hint
Check the 'Output Displayed' column at step 3 in the execution_table.
At which step does Terraform show an error for a missing output?
AStep 4
BStep 2
CStep 1
DStep 5
💡 Hint
Look for 'Error' in the 'Output Displayed' column in execution_table.
If you run 'terraform output -json', what will you see according to the execution_table?
AOnly one output value
BAll outputs in JSON format
CNo outputs, just a summary
DAn error message
💡 Hint
Refer to step 5 in the execution_table under 'Output Displayed'.
Concept Snapshot
Terraform output command:
- Use 'terraform output' to see values defined in outputs after apply.
- Outputs come from the state file storing resource info.
- Use 'terraform output <name>' for one output.
- Use '-json' flag for machine-readable output.
- Errors occur if output name is not defined.
Full Transcript
Terraform output command shows values defined as outputs in your Terraform configuration after resources are created. First, you run 'terraform apply' to create resources and save their info in the state file. Then, 'terraform output' reads this state file and displays the output values. You can get all outputs or a specific one by name. If you ask for an output that does not exist, Terraform shows an error. The '-json' flag shows outputs in JSON format for automation. This command only reads state; it does not create or change resources.