If you want a child module to receive a value from a parent module, what must you declare in the child module?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

If you want a child module to receive a value from a parent module, what must you declare in the child module?

Explanation:
To have a child module receive a value from its parent, you declare an input variable in the child module. This creates a placeholder that the parent can set when calling the module. For example, the child can declare a variable named node_count, and inside the child you reference it as var.node_count. The parent then passes a value when invoking the module, like node_count = some_value. Without declaring an input variable, the child has no way to accept the value from the parent, so Terraform cannot pass it through. A data source is for reading information from elsewhere, not for receiving values from a parent module, and a resource block creates infrastructure rather than enabling parameter passing. The idea illustrated by the option is that you need an input variable in the child module to receive the value.

To have a child module receive a value from its parent, you declare an input variable in the child module. This creates a placeholder that the parent can set when calling the module. For example, the child can declare a variable named node_count, and inside the child you reference it as var.node_count. The parent then passes a value when invoking the module, like node_count = some_value. Without declaring an input variable, the child has no way to accept the value from the parent, so Terraform cannot pass it through. A data source is for reading information from elsewhere, not for receiving values from a parent module, and a resource block creates infrastructure rather than enabling parameter passing. The idea illustrated by the option is that you need an input variable in the child module to receive the value.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy