nerdexam
HashiCorp

TERRAFORM-ASSOCIATE-004 · Question #190

Your root module contains a variable named num_servers. Which is the correct way to pass its value to a child module with an input named servers?

The correct answer is C. servers = var.num_servers. In Terraform, root module variables are referenced using the 'var.' prefix followed by the variable name: var.num_servers. To pass this into a child module, you write 'servers = var.num_servers' inside the module block. Option A ('servers = num_servers') is invalid - bare names w

Submitted by suresh_in· Apr 18, 2026Work with Terraform Modules

Question

Your root module contains a variable named num_servers. Which is the correct way to pass its value to a child module with an input named servers?

Options

  • Aservers = num_servers
  • Bservers = var(num_servers)
  • Cservers = var.num_servers
  • Dservers = ${var.num_servers}

How the community answered

(50 responses)
  • B
    2% (1)
  • C
    94% (47)
  • D
    4% (2)

Explanation

In Terraform, root module variables are referenced using the 'var.' prefix followed by the variable name: var.num_servers. To pass this into a child module, you write 'servers = var.num_servers' inside the module block. Option A ('servers = num_servers') is invalid - bare names without 'var.' are not valid references to input variables. Option B uses incorrect function-call syntax. Option D uses interpolation syntax from older Terraform versions combined with extra braces, which is invalid in modern HCL.

Topics

#Terraform variables#Module inputs#HCL syntax#Variable referencing

Community Discussion

No community discussion yet for this question.

Full TERRAFORM-ASSOCIATE-004 Practice