Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 221


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?

Show Answer
Correct Answer: AC

The correct way to define the output value in HCL2 syntax is to use the format shown in option A. In HCL2, you define an output block with a value that directly references the attribute of the resource. The value interpolation using the ${} syntax is not required in HCL2. Therefore, the correct syntax is: output "instance_ip_addr" { value = aws_instance.main.private_ip }. This is in line with the latest Terraform documentation and best practices.

Discussion

7 comments
Sign in to comment
sandyraoOption: A
Apr 1, 2023

answer should be A https://developer.hashicorp.com/terraform/language/values/outputs#declaring-an-output-value

oskarqOption: A
Apr 25, 2023

A is the new one but both would work: output "name-rg" { value = azurerm_resource_group.example.name } output "name-rg2" { value = "${azurerm_resource_group.example.name}" } Changes to Outputs: + name-rg = "example-resource-group" + name-rg2 = "example-resource-group"

tbhtpOption: A
Apr 1, 2023

its should be A. A output could look like this: output "example_output" { value = aws_instance.example.public_ip description = "The public IP address of the example instance." }

campsOption: A
Apr 1, 2023

It's A

KakashiCopyNinjaOption: A
Apr 9, 2023

It is A. See this documentation: https://developer.hashicorp.com/terraform/language/values/outputs

FarziWaliMarziOption: A
Apr 21, 2023

A for sure

wirkmoodOption: A
May 9, 2024

It's A.