Bird
Raised Fist0
Terraformcloud~20 mins

Outputs as documentation in Terraform - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Terraform Outputs Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate
2:00remaining
What is the output value of this Terraform output block?
Given the following Terraform output configuration, what will be the value shown after applying the configuration?
output "instance_ip" {
  value = aws_instance.web.public_ip
  description = "The public IP address of the web server instance"
}
Terraform
output "instance_ip" {
  value = aws_instance.web.public_ip
  description = "The public IP address of the web server instance"
}
AThe instance ID of the aws_instance named 'web'
BThe private IP address of the aws_instance named 'web'
CThe public IP address string of the aws_instance named 'web' after deployment
DAn error because description is not allowed in output blocks
Attempts:
2 left
💡 Hint
Think about what the 'value' field in an output block represents.
🧠 Conceptual
intermediate
1:30remaining
Why use output descriptions in Terraform?
Which of the following best explains the purpose of adding a description to a Terraform output block?
ATo change the output value dynamically during apply
BTo provide human-readable information about the output for users and maintainers
CTo encrypt the output value automatically
DTo prevent the output from being displayed after apply
Attempts:
2 left
💡 Hint
Think about what descriptions usually do in documentation.
❓ Configuration
advanced
2:30remaining
Which output block correctly documents and outputs the instance ID as a sensitive value?
Select the Terraform output block that outputs the instance ID of 'aws_instance.app' and marks it as sensitive with a clear description.
A
output "app_instance_id" {
  value = aws_instance.app.id
  sensitive = true
  description = "Sensitive instance ID of the app server"
}
B
output "app_instance_id" {
  value = aws_instance.app.id
  sensitive = yes
  description = "Sensitive instance ID of the app server"
}
C
output "app_instance_id" {
  value = aws_instance.app.id
  description = "Sensitive instance ID of the app server"
  sensitive = "true"
}
D
output "app_instance_id" {
  value = aws_instance.app.id
  sensitive = false
  description = "Sensitive instance ID of the app server"
}
Attempts:
2 left
💡 Hint
Check the correct syntax and data types for the 'sensitive' argument.
✅ Best Practice
advanced
2:00remaining
Which practice improves output documentation clarity in Terraform?
Which option best improves the clarity and usefulness of Terraform outputs for team members?
AAdd clear descriptions to all outputs explaining what they represent and their format
BOnly output raw resource IDs without descriptions to keep outputs minimal
CUse outputs only for internal Terraform modules, not for external use
DAvoid using outputs to prevent exposing any resource information
Attempts:
2 left
💡 Hint
Think about how documentation helps teams understand infrastructure.
❓ Architecture
expert
3:00remaining
How does output documentation affect multi-environment Terraform deployments?
In a Terraform setup managing multiple environments (dev, staging, prod), how does well-documented outputs help architects and operators?
AIt automatically syncs outputs between environments without manual intervention
BIt encrypts outputs differently per environment to enhance security
CIt disables outputs in non-production environments to save resources
DIt helps quickly identify which outputs correspond to which environment and their purpose, reducing mistakes during deployments
Attempts:
2 left
💡 Hint
Think about how documentation helps when managing many similar setups.

Practice

(1/5)
1. What is the main purpose of output blocks in Terraform?
easy
A. To write resource creation logic
B. To define variables for input values
C. To display important information after infrastructure is created
D. To configure provider settings

Solution

  1. Step 1: Understand output block role

    Output blocks are used to show key information after Terraform finishes applying changes.
  2. Step 2: Differentiate from other blocks

    Variables define inputs, providers configure cloud access, and resources create infrastructure, so outputs are for displaying results.
  3. Final Answer:

    To display important information after infrastructure is created -> Option C
  4. Quick Check:

    Outputs = display info [OK]
Hint: Outputs show info after apply, not inputs or configs [OK]
Common Mistakes:
  • Confusing outputs with variables
  • Thinking outputs create resources
  • Assuming outputs configure providers
2. Which of the following is the correct syntax to define an output with a description in Terraform?
easy
A. output ip_address { value = aws_instance.web.public_ip description = "Public IP address" }
B. output "ip_address" { value = aws_instance.web.public_ip description = "Public IP address" }
C. output "ip_address" { value = aws_instance.web.public_ip } description = "Public IP address"
D. output "ip_address" { value = aws_instance.web.public_ip desc = "Public IP address" }

Solution

  1. Step 1: Check output block structure

    An output block requires a name, a value, and optionally a description inside curly braces.
  2. Step 2: Verify correct syntax

    The correct syntax places each attribute on its own line or separated properly; output "ip_address" { value = aws_instance.web.public_ip description = "Public IP address" } shows the correct format with value and description.
  3. Final Answer:

    output "ip_address" { value = aws_instance.web.public_ip description = "Public IP address" } -> Option B
  4. Quick Check:

    Output syntax = name, value, description [OK]
Hint: Output blocks need name, value, description inside braces [OK]
Common Mistakes:
  • Missing quotes around output name
  • Placing description outside the block
  • Using incorrect attribute names
3. Given this Terraform output block:
output "db_password" {
  value       = aws_db_instance.main.password
  sensitive   = true
  description = "The database password"
}

What will happen when you run terraform apply?
medium
A. The password will not be shown in the output because it is marked sensitive
B. Terraform will throw a syntax error due to sensitive attribute
C. The password will be shown in the output after apply
D. The password will be printed in plain text in the logs

Solution

  1. Step 1: Understand sensitive attribute effect

    Marking an output as sensitive hides its value from the standard output to protect secrets.
  2. Step 2: Predict terraform apply behavior

    Terraform will apply changes but will not display the sensitive value in the output summary.
  3. Final Answer:

    The password will not be shown in the output because it is marked sensitive -> Option A
  4. Quick Check:

    sensitive output hides value [OK]
Hint: Sensitive outputs hide values after apply [OK]
Common Mistakes:
  • Assuming sensitive outputs print values
  • Thinking sensitive causes errors
  • Confusing sensitive with encryption
4. You wrote this output block:
output "instance_ip" {
value = aws_instance.web.public_ip
}

Terraform shows a warning about missing description. How do you fix it?
medium
A. Rename the output to "instance_ip_address"
B. Remove the output block completely
C. Change value to a string literal
D. Add a description attribute inside the output block

Solution

  1. Step 1: Identify missing description

    Terraform recommends adding descriptions to outputs for clarity and documentation.
  2. Step 2: Add description attribute

    Include a line like description = "Public IP of the instance" inside the output block to fix the warning.
  3. Final Answer:

    Add a description attribute inside the output block -> Option D
  4. Quick Check:

    Outputs need descriptions for docs [OK]
Hint: Add description attribute to output blocks [OK]
Common Mistakes:
  • Ignoring description warnings
  • Changing output name unnecessarily
  • Removing output instead of fixing
5. You want to output a list of public IPs from multiple instances created with a for_each in Terraform. Which output block correctly documents and outputs this list?
hard
A. output "instance_ips" { value = [for inst in aws_instance.web : inst.public_ip] description = "List of public IPs for all web instances" }
B. output "instance_ips" { value = aws_instance.web.public_ip description = "List of public IPs for all web instances" }
C. output "instance_ips" { value = tolist(aws_instance.web.public_ip) description = "List of public IPs for all web instances" }
D. output "instance_ips" { value = aws_instance.web.public_ip[0] description = "List of public IPs for all web instances" }

Solution

  1. Step 1: Understand for_each resource outputs

    When using for_each, resources are a map, so to get all public IPs, a for expression is needed to collect them.
  2. Step 2: Check output value expression

    output "instance_ips" { value = [for inst in aws_instance.web : inst.public_ip] description = "List of public IPs for all web instances" } uses a for expression to iterate over all instances and extract public_ip, which is correct and documented with description.
  3. Final Answer:

    output "instance_ips" { value = [for inst in aws_instance.web : inst.public_ip] description = "List of public IPs for all web instances" } -> Option A
  4. Quick Check:

    Use for expression to output list from for_each [OK]
Hint: Use for expression to collect values from for_each resources [OK]
Common Mistakes:
  • Using direct attribute without iteration
  • Accessing only first element
  • Using incorrect syntax for list extraction