0
0
Terraformcloud~10 mins

Why outputs expose useful information in Terraform - Test Your Understanding

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's public IP.

Terraform
output "instance_ip" {
  value = [1]
}
Drag options to blanks, or click blank then click option'
Aaws_instance.example.public_ip
Baws_instance.example.private_ip
Caws_instance.example.id
Daws_instance.example.arn
Attempts:
3 left
💡 Hint
Common Mistakes
Using private_ip instead of public_ip.
Using instance ID or ARN which are not IP addresses.
2fill in blank
medium

Complete the code to output the database endpoint after creation.

Terraform
output "db_endpoint" {
  value = [1]
}
Drag options to blanks, or click blank then click option'
Aaws_db_instance.main.port
Baws_db_instance.main.id
Caws_db_instance.main.address
Daws_db_instance.main.endpoint
Attempts:
3 left
💡 Hint
Common Mistakes
Using the database ID or port instead of the endpoint.
Using an attribute that does not provide connection info.
3fill in blank
hard

Fix the error in the output block to correctly expose the load balancer DNS name.

Terraform
output "lb_dns" {
  value = aws_lb.example.[1]
}
Drag options to blanks, or click blank then click option'
Aname
Bhostname
Cdns_name
Durl
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' which is just the resource name.
Using 'hostname' or 'url' which are not valid attributes.
4fill in blank
hard

Fill both blanks to output the subnet IDs from a list of subnets.

Terraform
output "subnet_ids" {
  value = [for subnet in [1] : subnet.[2]]
}
Drag options to blanks, or click blank then click option'
Aaws_subnet.example
Baws_subnet.example.*
Cid
Dsubnet_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single resource instead of a list.
Using 'subnet_id' which is not a valid attribute.
5fill in blank
hard

Fill all three blanks to output a map of instance names to their private IPs, filtering only running instances.

Terraform
output "running_instances" {
  value = { for i in [1] : i.[2] => i.[3] if i.instance_state.name == "running" }
}
Drag options to blanks, or click blank then click option'
Aaws_instance.all
Btags.Name
Cprivate_ip
Daws_instance.example
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single instance resource instead of a list.
Using incorrect attributes for name or IP.
Not filtering by running state.