0
0
Terraformcloud~20 mins

Module inputs (variables) in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Module Inputs Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Terraform module variable defaults
Given a Terraform module with a variable defined as variable "region" { default = "us-west-1" }, what will be the value of var.region inside the module if the caller does NOT provide a value?
A"us-west-1"
Bnull
CAn error occurs because the variable is not set
D"us-east-1"
Attempts:
2 left
💡 Hint
Think about what happens when a variable has a default value and no override is given.
Configuration
intermediate
2:00remaining
Passing variables to a Terraform module
You have a Terraform module that expects a variable instance_count. Which of the following is the correct way to pass the value 3 to this variable when calling the module?
Terraform
module "webserver" {
  source = "./modules/webserver"
  // fill in here
}
Aset instance_count 3
Binstance_count = 3
Cvar.instance_count = 3
Dvariable "instance_count" = 3
Attempts:
2 left
💡 Hint
Remember how to assign values to module inputs in the module block.
Architecture
advanced
2:00remaining
Variable type constraints in Terraform modules
A module variable is defined as variable "tags" { type = map(string) }. Which of the following values passed to this variable will cause a Terraform plan error?
A{}
B{ "Environment" = "prod", "Owner" = "team-a" }
C{ Environment = "prod", Owner = "team-a" }
D["prod", "team-a"]
Attempts:
2 left
💡 Hint
Consider the expected type and what each option represents.
security
advanced
2:00remaining
Sensitive variables in Terraform modules
You want to pass a password to a Terraform module variable without showing it in logs or state files. Which variable attribute should you use inside the module to mark it as sensitive?
Asensitive = true
Bhidden = true
Cprivate = true
Dsecure = true
Attempts:
2 left
💡 Hint
Terraform has a specific attribute to mark variables as sensitive.
service_behavior
expert
2:00remaining
Effect of missing required module variables
A Terraform module defines a variable project_id without a default value. The caller does NOT provide a value for this variable. What happens when you run terraform apply?
ATerraform fails with an error about the missing variable
BTerraform applies using a null value for the variable
CTerraform prompts for the missing variable value before applying
DTerraform applies with an empty string as the variable value
Attempts:
2 left
💡 Hint
Think about how Terraform handles required variables without defaults and no input.