Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 130


You are writing a child Terraform module which provisions an AWS instance. You want to make use of the IP address returned in the root configuration. You name the instance resource "main".

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

A.

B.

Show Answer
Correct Answer:

The correct way to define the output value using HCL2 is to use the provided syntax of 'value = aws_instance.main.private_ip' without the interpolation syntax using ${}. Therefore, the correct answer is option A, but with the updated HCL2 syntax. Option A correctly uses a 'value' attribute, while option B incorrectly uses 'return', which is not valid in Terraform configuration.

Discussion

7 comments
Sign in to comment
keiffo2
Mar 6, 2023

Has to be Answer A. no such definition as "return"

MauroSoli
Apr 25, 2024

Answer is A but syntax is deprecated

Bere
Jul 16, 2024

Answer is A In Terraform versions 0.11 and earlier, you would use the interpolation syntax with ${} to reference attributes: # Terraform 0.11 and earlier output "instance_ip_addr" { value = "${aws_instance.main.private_ip}" } Starting with Terraform 0.12, interpolation is not needed for simple references, so you can directly reference the attribute: # Terraform 0.12 and later output "instance_ip_addr" { value = aws_instance.main.private_ip }

kennynelcon
Aug 11, 2023

A is accurate

phidelics
Sep 22, 2023

The answer is A

junk4share
Jan 11, 2024

A is correct.

syam22587
Feb 23, 2024

A is correct answer