What is the proper way to expose a resource attribute from a child module to the root module?

Prepare for the HashiCorp Terraform Associate Exam. Utilize flashcards and multiple-choice questions with detailed hints and explanations. Boost your confidence and be ready for success!

Multiple Choice

What is the proper way to expose a resource attribute from a child module to the root module?

Explanation:
Exposing a value from a child module to the root module is done with an output in the child module. Outputs are how a module returns data to its caller, so you declare an output for the resource attribute you want to share. Then in the root module you can reference it as module.<child_name>.<output_name> and use that value for other resources or final outputs. Variables belong to the child as inputs, so they must be provided by the caller and don’t publish the child’s generated data. Environment variables aren’t Terraform’s mechanism for sharing data between modules, and data sources are used to fetch information from providers, not to pass a produced attribute up from a child module.

Exposing a value from a child module to the root module is done with an output in the child module. Outputs are how a module returns data to its caller, so you declare an output for the resource attribute you want to share. Then in the root module you can reference it as module.. and use that value for other resources or final outputs. Variables belong to the child as inputs, so they must be provided by the caller and don’t publish the child’s generated data. Environment variables aren’t Terraform’s mechanism for sharing data between modules, and data sources are used to fetch information from providers, not to pass a produced attribute up from a child module.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy