Exam Terraform Associate All QuestionsBrowse all questions from this 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?

    Correct Answer: A

    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
oskarqOption: A

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"

sandyraoOption: A

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

wirkmoodOption: A

It's A.

FarziWaliMarziOption: A

A for sure

KakashiCopyNinjaOption: A

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

campsOption: A

It's A

tbhtpOption: A

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." }