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

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 of the variable num_servers into a module input named servers in HCL2?

Explanation:
In Terraform modules, you pass values to inputs by assigning to the input name with equals, and you reference variables from the calling module using var.name. Therefore, to pass the value of num_servers into the module input named servers, you write servers = var.num_servers. This uses the correct variable reference syntax and assignment. The other options fail because they use invalid syntax for module arguments (a dash), an incorrect way to reference a variable (var(num_servers)), or a shell-like substitution form ($(…)) that isn’t valid in HCL.

In Terraform modules, you pass values to inputs by assigning to the input name with equals, and you reference variables from the calling module using var.name. Therefore, to pass the value of num_servers into the module input named servers, you write servers = var.num_servers. This uses the correct variable reference syntax and assignment. The other options fail because they use invalid syntax for module arguments (a dash), an incorrect way to reference a variable (var(num_servers)), or a shell-like substitution form ($(…)) that isn’t valid in HCL.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy