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

You are using a networking module in your Terraform configuration with the name label my_network. In your main configuration you have the following code:

When you run terraform validate, you get the following error:

What must you do to successfully retrieve this value from your networking module?

    Correct Answer: C

    To successfully retrieve a value from a module in Terraform, you must define that value as an output in the module. In the given scenario, the attribute vnet_id should be defined as an output within the networking module (my_network). By doing so, the main configuration can reference this output value correctly using module.my_network.vnet_id. Therefore, defining the attribute vnet_id as an output in the networking module is the correct approach.

Discussion
zyxphreezOption: C

In a parent module, outputs of child modules are available in expressions as module.<MODULE NAME>.<OUTPUT NAME>. For example, if a child module named web_server declared an output named instance_ip_addr, you could access that value as module.web_server.instance_ip_addr. Answer is C

RVivekOption: C

Create an out put in child module and resfrence that as module.<MODULE NAME>.<OUTPUT NAME>

BereOption: A

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 }

BereOption: C

Answer is C Define the attribute vnet_id as an output in the networking module. In the Child Module (my_network), if you had a resource defined as aws_vpc and named it example_vpc, you would reference its ID like this: # In your networking module's outputs.tf or main.tf file output "vnet_id" { description = "The ID of the created VNet" value = aws_vpc.example_vpc.id # Replace example_vpc with the actual name of your VPC resource } In the Parent Module (main configuration): output "net_id" { value = module.my_network.vnet_id }

WilliamusOption: C

All looks good except that the output in the child module is missing.

JayanthOption: C

C is the right answer