0
0
Terraformcloud~10 mins

Outputs as documentation in Terraform - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define an output that shows the instance ID.

Terraform
output "instance_id" {
  value = [1]
}
Drag options to blanks, or click blank then click option'
Aaws_instance.example.type
Baws_instance.example.name
Caws_instance.example.id
Daws_instance.example.region
Attempts:
3 left
💡 Hint
Common Mistakes
Using the instance name instead of the ID.
Using the resource type property instead of the ID.
2fill in blank
medium

Complete the code to add a description to the output.

Terraform
output "instance_ip" {
  value       = aws_instance.example.public_ip
  description = [1]
}
Drag options to blanks, or click blank then click option'
A"The public IP address of the instance"
Binstance_ip
C"Instance public IP"
DThe public IP address of the instance
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the description.
Using a variable name instead of a descriptive string.
3fill in blank
hard

Fix the error in the output block to correctly reference the subnet ID.

Terraform
output "subnet_id" {
  value = aws_subnet.example[1]
}
Drag options to blanks, or click blank then click option'
A.name
B[0]
C.subnet_id
D.id
Attempts:
3 left
💡 Hint
Common Mistakes
Using .subnet_id which is not a valid attribute.
Using .name which is not the ID.
4fill in blank
hard

Fill both blanks to output the list of security group IDs and add a description.

Terraform
output "security_group_ids" {
  value       = aws_security_group.example[1]
  description = [2]
}
Drag options to blanks, or click blank then click option'
A.*.id
B"List of security group IDs"
C"Security groups attached"
D.id
Attempts:
3 left
💡 Hint
Common Mistakes
Using .id instead of .* .id for lists.
Not quoting the description string.
5fill in blank
hard

Fill all three blanks to output a map of instance names to their private IPs with a description.

Terraform
output "instance_private_ips" {
  value       = { for inst in aws_instance.example : inst[1] => inst[2] }
  description = [3]
}
Drag options to blanks, or click blank then click option'
A.tags.Name
B.private_ip
C"Mapping of instance names to private IP addresses"
D.id
Attempts:
3 left
💡 Hint
Common Mistakes
Using .id instead of .tags.Name for keys.
Not quoting the description string.