0
0
Terraformcloud~10 mins

Why modules enable reusability in Terraform - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a module block in Terraform.

Terraform
module "example" {
  source = [1]
}
Drag options to blanks, or click blank then click option'
A"variable"
B"aws_instance"
C"./modules/example"
D"terraform"
Attempts:
3 left
💡 Hint
Common Mistakes
Using resource type names instead of a path for source.
Leaving source empty or with invalid strings.
2fill in blank
medium

Complete the code to pass a variable to a module.

Terraform
module "example" {
  source = "./modules/example"
  instance_type = [1]
}
Drag options to blanks, or click blank then click option'
A"variable"
B"t2.micro"
Ct2.micro
Dinstance_type
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around string values.
Using variable names without quotes as values.
3fill in blank
hard

Fix the error in the module output block.

Terraform
output "instance_id" {
  value = module.example.[1]
}
Drag options to blanks, or click blank then click option'
Ainstance_id
Binstance
Cid
Doutput_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using resource attribute names instead of output names.
Using incorrect or partial output names.
4fill in blank
hard

Fill both blanks to define a reusable module with variables and outputs.

Terraform
variable "[1]" {
  type = string
}

output "[2]" {
  value = var.[1]
}
Drag options to blanks, or click blank then click option'
Ainstance_type
Binstance_id
Dinstance_name
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable and output names.
Using the same name for both variable and output.
5fill in blank
hard

Fill all three blanks to call a module with variables and use its output.

Terraform
module "web" {
  source = [1]
  instance_type = [2]
}

output "web_id" {
  value = module.web.[3]
}
Drag options to blanks, or click blank then click option'
A"./modules/webserver"
B"t3.small"
Cinstance_id
D"aws_instance"
Attempts:
3 left
💡 Hint
Common Mistakes
Using resource types instead of paths for source.
Omitting quotes around string values.
Referencing wrong output names.