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
Recall & Review
beginner
What is the main purpose of outputs in Terraform?
Outputs in Terraform show important information after deployment, like IP addresses or URLs, so you can use or share them easily.
Click to reveal answer
beginner
How can outputs help as documentation in Terraform?
Outputs describe key values your infrastructure creates, making it clear what resources are available and how to connect to them.
Click to reveal answer
beginner
Which Terraform block is used to define an output?
The `output` block defines an output value with a name and description.
Click to reveal answer
beginner
Why should you add a description to Terraform outputs?
Descriptions explain what the output means, helping others understand the infrastructure without guessing.
Click to reveal answer
intermediate
Can Terraform outputs be used by other Terraform configurations?
Yes, outputs can be shared and used as inputs in other Terraform projects, enabling modular and connected infrastructure.
Click to reveal answer
What Terraform block do you use to show a value after deployment?
Aprovider
Bvariable
Cresource
Doutput
✗ Incorrect
The `output` block is used to display values after Terraform applies changes.
Why add a description to an output in Terraform?
ATo hide the output value
BTo explain the output's meaning
CTo change the output value
DTo delete the output
✗ Incorrect
Descriptions help users understand what the output represents.
Which of these is NOT a good use of Terraform outputs?
AStoring sensitive passwords in plain text
BShowing server IP addresses
CSharing resource IDs with other configs
DDisplaying URLs of deployed services
✗ Incorrect
Sensitive data should be handled carefully, not exposed in plain text outputs.
How do outputs help with documentation?
AThey list important info about deployed resources
BThey delete unused resources
CThey speed up deployment
DThey encrypt data
✗ Incorrect
Outputs provide clear info about what your infrastructure created.
Can outputs be used as inputs in other Terraform projects?
AOnly if they are strings
BNo, outputs are only for display
CYes, to connect different configurations
DOnly if they are numbers
✗ Incorrect
Outputs can be passed as inputs to other Terraform configurations for modular design.
Explain how Terraform outputs serve as documentation for your infrastructure.
Think about how outputs tell you what your infrastructure created.
You got /4 concepts.
Describe best practices when defining outputs in Terraform.
Consider clarity, security, and reusability.
You got /4 concepts.
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
Step 1: Understand output block role
Output blocks are used to show key information after Terraform finishes applying changes.
Step 2: Differentiate from other blocks
Variables define inputs, providers configure cloud access, and resources create infrastructure, so outputs are for displaying results.
Final Answer:
To display important information after infrastructure is created -> Option C
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
Step 1: Check output block structure
An output block requires a name, a value, and optionally a description inside curly braces.
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.
Final Answer:
output "ip_address" { value = aws_instance.web.public_ip description = "Public IP address" } -> Option B
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
Step 1: Understand sensitive attribute effect
Marking an output as sensitive hides its value from the standard output to protect secrets.
Step 2: Predict terraform apply behavior
Terraform will apply changes but will not display the sensitive value in the output summary.
Final Answer:
The password will not be shown in the output because it is marked sensitive -> Option A
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
Step 1: Identify missing description
Terraform recommends adding descriptions to outputs for clarity and documentation.
Step 2: Add description attribute
Include a line like description = "Public IP of the instance" inside the output block to fix the warning.
Final Answer:
Add a description attribute inside the output block -> Option D
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
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.
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.
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
Quick Check:
Use for expression to output list from for_each [OK]
Hint: Use for expression to collect values from for_each resources [OK]