Hashicorp Certified Terraform Associate 003 · Free Practice Question Medium

Question 3

A child module created a new subnet for some new workloads. What Terraform block type would allow you to pass the subnet ID back to the parent module?

  • A

    terraform block

  • B

    data block

  • C

    output block

  • D

    resource block

Reveal correct answer

Correct answer: C

Explanation

The resources defined in a module are encapsulated, so the parent module cannot access their attributes directly. However, the child module can declare output values to selectively export certain values to be accessed by the calling module.


https://developer.hashicorp.com/terraform/language/modules/syntax#accessing-module-output-values

A.

The terraform block is used to configure global settings for a Terraform configuration, such as the required Terraform version or backend configuration. It is not used for passing values between modules, so it is not the correct choice for passing the subnet ID back to the parent module.

B.

The data block is used to define data sources in Terraform, such as information retrieved from external sources like APIs or databases. It is not used to pass values between modules, so it is not the correct choice for passing the subnet ID back to the parent module.

C.

The correct choice is the output block. This block type in Terraform allows you to define values that can be passed back to the parent module. In this case, the subnet ID created by the child module can be defined as an output value and accessed by the parent module for further use.

D.

The resource block is used to define and manage infrastructure resources in Terraform. It is not used for passing values between modules, so it is not the correct choice for passing the subnet ID back to the parent module. The output block is specifically designed for this purpose.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need