How do you pass input variables to a Terraform module?

  1. Using the "variables" block in the module call ✓
  2. By modifying the provider configuration
  3. Via command-line flags during terraform init
  4. Through environment variables only

Correct answer: Using the "variables" block in the module call

Option A is correct because when calling a Terraform module, input variables are passed using argument assignments within the module block itself, where each declared variable in the child module is supplied as a named argument in the calling module block. Option B is incorrect because the provider configuration block defines cloud provider credentials and settings, not module input variable values. Option C is incorrect because terraform init initializes the working directory and downloads providers and modules, and does not accept variable values as flags. Option D is incorrect because while environment variables prefixed with TF_VAR_ can set root module variables, they are not the standard or recommended mechanism for passing values to child modules; module arguments in the module block are the correct approach.

Topic: · terraform modules, input variables, infrastructure as code, hashicorp terraform

Practice HashiCorp Terraform Associate (003) Questions Free