Which is the correct way to pass the value in the variable num_servers into a module with the input servers?

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

Which is the correct way to pass the value in the variable num_servers into a module with the input servers?

Explanation:
Passing values into a module's input variable is done by assigning the module input with an expression from the calling context. In Terraform, values defined in the root module are accessed as var.<name>. To pass the number of servers into the module, you set the module input like servers = var.num_servers inside the module block. This is the correct form because it references the actual variable defined in the root module and feeds its value into the module’s servers input. The other forms don’t work: omitting var. would reference a symbol that doesn’t exist in the caller, leading to an error; using variable.num_servers is not a valid reference in Terraform; and including a stray closing parenthesis is a syntax error.

Passing values into a module's input variable is done by assigning the module input with an expression from the calling context. In Terraform, values defined in the root module are accessed as var.. To pass the number of servers into the module, you set the module input like servers = var.num_servers inside the module block. This is the correct form because it references the actual variable defined in the root module and feeds its value into the module’s servers input.

The other forms don’t work: omitting var. would reference a symbol that doesn’t exist in the caller, leading to an error; using variable.num_servers is not a valid reference in Terraform; and including a stray closing parenthesis is a syntax error.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy