0
0
Terraformcloud~10 mins

Outputs as documentation in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Outputs as documentation
Define output block
Assign value and description
Run terraform apply
Terraform stores output
Run terraform output
Display output value and description
Outputs are defined in Terraform to show important info after deployment, helping document what was created.
Execution Sample
Terraform
output "instance_ip" {
  value       = aws_instance.web.public_ip
  description = "The public IP of the web server instance"
}
This output block shows the public IP of a created AWS instance with a helpful description.
Process Table
StepActionEvaluationResult
1Terraform reads output blockParses value and descriptionOutput 'instance_ip' defined with value and description
2terraform apply runsCreates aws_instance.webInstance created with public IP assigned
3Terraform stores output valueCaptures aws_instance.web.public_ipOutput value saved
4User runs 'terraform output'Fetches stored outputsDisplays 'instance_ip' value
5User reads outputSees IP and descriptionUnderstands what resource IP is for
6EndNo more outputsExecution stops
💡 All outputs displayed after apply; no further outputs to show
Status Tracker
VariableStartAfter ApplyAfter Output Command
instance_ipundefined54.123.45.6754.123.45.67
Key Moments - 3 Insights
Why do we add a description to an output?
The description helps users understand what the output value means, as shown in step 4 of the execution_table where the output is displayed with its description.
When is the output value available to see?
The output value is only available after 'terraform apply' runs successfully and creates the resource, as shown in step 3 where the value is stored.
Can outputs show values before resources are created?
No, outputs depend on resource values created during apply, so before apply the output value is undefined, as shown in variable_tracker start state.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does Terraform store the output value?
AStep 4
BStep 2
CStep 3
DStep 1
💡 Hint
Check the 'Evaluation' column in step 3 where it says 'Captures aws_instance.web.public_ip'
According to variable_tracker, what is the value of 'instance_ip' before 'terraform apply'?
A54.123.45.67
Bundefined
Cnull
D0.0.0.0
💡 Hint
Look at the 'Start' column for 'instance_ip' in variable_tracker
If the description was missing from the output block, what would change in the execution_table output display?
AThe output value would show but without description
BThe output value would not be shown
CTerraform apply would fail
DThe output would show an error
💡 Hint
Step 4 shows output value and description; description is optional but helps users
Concept Snapshot
Terraform outputs show important info after deployment.
Define with 'output' block: value and optional description.
Run 'terraform apply' to create resources.
Run 'terraform output' to see values.
Descriptions help document outputs for users.
Full Transcript
Terraform outputs are blocks that let you show key information after your infrastructure is created. You define an output with a name, a value (usually from a resource), and an optional description to explain what it means. When you run 'terraform apply', Terraform creates the resources and captures the output values. Later, running 'terraform output' displays these values along with their descriptions. This helps users understand what was created and how to use the outputs. Outputs are only available after resources exist, so before apply they are undefined. Adding descriptions is a best practice to document your infrastructure clearly.