0
0
Terraformcloud~10 mins

Module composition patterns in Terraform - Interactive Code Practice

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

Complete the code to declare a module source.

Terraform
module "network" {
  source = [1]
}
Drag options to blanks, or click blank then click option'
A"aws_vpc"
B"./modules/network"
C"terraform.io/modules"
D"network_module"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a module name instead of a path for source.
Omitting quotes around the source path.
2fill in blank
medium

Complete the code to pass a variable to a module.

Terraform
module "compute" {
  source = "./modules/compute"
  instance_type = [1]
}
Drag options to blanks, or click blank then click option'
A"t2.micro"
Bt2.micro
Cinstance_type
Dvar.instance_type
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around string values.
Using variable names without the var. prefix.
3fill in blank
hard

Fix the error in the module call to correctly reference an output.

Terraform
output "subnet_id" {
  value = module.network.[1]
}
Drag options to blanks, or click blank then click option'
Asubnet-id
Bsubnet
CsubnetId
Dsubnet_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase or hyphens instead of underscores.
Referencing outputs that do not exist in the module.
4fill in blank
hard

Fill both blanks to create a module block with a variable and output reference.

Terraform
module "storage" {
  source = [1]
  bucket_name = [2]
}

output "bucket" {
  value = module.storage.bucket_name
}
Drag options to blanks, or click blank then click option'
A"./modules/storage"
B"my-bucket"
Cvar.bucket_name
D"bucket_name"
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable references without defining them.
Not quoting string values.
5fill in blank
hard

Fill all three blanks to define a module with variables and use an output in another resource.

Terraform
module "db" {
  source = [1]
  db_name = [2]
  db_user = [3]
}

resource "aws_db_instance" "main" {
  identifier = module.db.db_name
  username = module.db.db_user
  engine = "mysql"
  instance_class = "db.t3.micro"
}
Drag options to blanks, or click blank then click option'
A"./modules/database"
B"mydatabase"
C"admin"
D"database_module"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names.
Not quoting string values.