What is the purpose of the variables.tf file inside the module?
medium
A. To declare output values from the module
B. To define input variables for the module
C. To write the main resource definitions
D. To store provider configurations
Solution
Step 1: Understand file roles in module
In Terraform modules, variables.tf defines input variables the module accepts.
Step 2: Match options
To define input variables for the module correctly states this. Outputs are in outputs.tf, main resources in main.tf, and provider configs are outside modules.
Final Answer:
To define input variables for the module -> Option B
But Terraform shows an error: "Unsupported argument: db_name". What is the likely cause?
medium
A. The source path is incorrect
B. Module names cannot contain underscores
C. The module does not declare an input variable named db_name
D. db_name should be declared inside main.tf
Solution
Step 1: Understand error meaning
"Unsupported argument" means the module does not expect the given input variable.
Step 2: Check module inputs
If db_name is not declared as a variable in the module's variables.tf, Terraform rejects it.
Final Answer:
The module does not declare an input variable named db_name -> Option C
Quick Check:
Input variables must be declared to be used [OK]
Hint: Declare input variables in module to avoid unsupported argument errors [OK]
Common Mistakes:
Assuming source path causes unsupported argument
Thinking module names restrict underscores
Trying to declare inputs inside main.tf
5. You want to create a reusable module for deploying a virtual machine with optional tags. Which structure correctly supports optional tags with a default empty map?
hard
A. In variables.tf: variable "tags" { type = list(string) }
B. In main.tf: variable "tags" { default = null }
C. In outputs.tf: output "tags" { value = var.tags }
D. In variables.tf: variable "tags" { type = map(string) default = {} }
Solution
Step 1: Define optional input variable
To make tags optional, define a variable with type map(string) and default empty map {}.
Step 2: Evaluate options
In variables.tf: variable "tags" { type = map(string) default = {} } correctly defines this in variables.tf. In main.tf: variable "tags" { default = null } lacks type and uses null default. In outputs.tf: output "tags" { value = var.tags } is output, not input. In variables.tf: variable "tags" { type = list(string) } uses list instead of map.
Final Answer:
In variables.tf: variable "tags" { type = map(string) default = {} } -> Option D