Exam Terraform Associate All QuestionsBrowse all questions from this exam
Question 320

You are writing a child Terraform module that provisions an AWS instance. You want to reference the IP address returned by the child module in the root configuration. You name the instance resource "main".

Which of these is the correct way to define the output value?

    Correct Answer: A

    To define an output value for the IP address returned by a child Terraform module, you need to use the 'output' block with the 'value' argument containing the expression that returns the desired value. The expression should refer to the attribute exposed by the resource. In this case, 'aws_instance.main.private_ip' is a valid expression that gets the private IP of the instance named 'main'. Therefore, option A correctly defines the output value.

Discussion
akbiyikOption: A

Each output value exported by a module must be declared using an output block: output "instance_ip_addr" { value = aws_instance.server.private_ip } The value argument takes an expression whose result is to be returned to the user. In this example, the expression refers to the private_ip attribute exposed by an aws_instance resource defined elsewhere in this module (not shown). Any valid expression is allowed as an output value. https://developer.hashicorp.com/terraform/language/values/outputs