HashiCorp Terraform Associate Practice Exam

Session length

1 / 20

What is the correct syntax to define an output in a Terraform module to expose the public IP of an aws_instance named 'web'?

output "ip" { value = aws_instance.web.public_ip }

Outputs in a Terraform module are how you expose values to the module’s caller. To reveal the public IP of an aws_instance named web, you define an output and set its value to the resource’s attribute. The correct approach uses the resource reference format: aws_instance.web.public_ip, placed inside an output block. So the valid form is output "ip" { value = aws_instance.web.public_ip }. This makes the instance’s public IP available to whatever module consumes this one.

Other patterns aren’t appropriate here. export isn’t Terraform syntax for outputs, and var.ip would just pass in a value from a variable rather than expose the resource’s attribute. Referencing module.web.public_ip would point to a child module’s output, not to the aws_instance resource within this module.

output "ip" { value = module.web.public_ip }

export ip = aws_instance.web.public_ip

output "ip" { value = var.ip }

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy