HashiCorp Certified: Terraform Associate — Question 210
Which of the following is the correct way to pass the value in the variable num_servers into a module with the input server?
Answer options
- A. servers = var(num_servers)
- B. $(var.num_servers)
- C. servers = num_servers
- D. servers = var.num_servers
Correct answer: D
Explanation
The correct answer is D because it correctly references the variable using the var() syntax, allowing the module to access the value of num_servers. Option A is incorrect as it uses an improper syntax for accessing the variable. Option B is not valid in this context as it uses a command substitution syntax rather than a variable reference. Option C fails to use the var() function, which is necessary for module input assignments.