0
0
Terraformcloud~20 mins

Module composition patterns in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Module Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Architecture
intermediate
2:00remaining
Understanding Module Composition with Terraform

You have a Terraform root module that calls two child modules: network and compute. The compute module requires the VPC ID output from the network module. Which is the correct way to pass the VPC ID from network to compute?

Terraform
module "network" {
  source = "./modules/network"
}

module "compute" {
  source = "./modules/compute"
  vpc_id = ???
}
Avpc_id = module.network.vpc_id
Bvpc_id = output.network.vpc_id
Cvpc_id = var.network.vpc_id
Dvpc_id = local.network.vpc_id
Attempts:
2 left
💡 Hint

Think about how Terraform modules expose outputs and how other modules can access them.

Configuration
intermediate
2:00remaining
Correct Module Source Usage

You want to reuse a Terraform module stored in a GitHub repository. Which source value correctly references the module?

Terraform
module "storage" {
  source = ???
  version = "1.0.0"
}
A"git::https://github.com/terraform-modules/storage.git"
B"https://github.com/terraform-modules/storage"
C"github.com/terraform-modules/storage"
D"terraform-registry/storage"
Attempts:
2 left
💡 Hint

Terraform requires a specific syntax to fetch modules from Git repositories.

security
advanced
2:00remaining
Secure Module Composition with Sensitive Variables

You have a root module that calls a child module which requires a sensitive API key. How should you pass this sensitive variable to avoid exposing it in Terraform state or logs?

Terraform
module "service" {
  source = "./modules/service"
  api_key = ???
}
Aapi_key = "hardcoded-secret"
Bapi_key = local.api_key
Capi_key = var.api_key
Dapi_key = output.api_key
Attempts:
2 left
💡 Hint

Consider how Terraform handles sensitive variables and best practices for secrets.

service_behavior
advanced
2:00remaining
Effect of Module Dependency on Resource Creation Order

Given two modules, db and app, where app depends on the database endpoint output from db, what is the effect on resource creation order when you run terraform apply?

Terraform
module "db" {
  source = "./modules/db"
}

module "app" {
  source = "./modules/app"
  db_endpoint = module.db.endpoint
}
ATerraform creates <code>app</code> and <code>db</code> resources in parallel without order.
BTerraform creates <code>db</code> resources first, then <code>app</code> resources after <code>db</code> outputs are available.
CTerraform creates <code>app</code> resources first, then <code>db</code> resources.
DTerraform fails because modules cannot depend on each other.
Attempts:
2 left
💡 Hint

Think about how Terraform manages dependencies between modules using outputs and inputs.

Best Practice
expert
3:00remaining
Optimizing Module Composition for Reusability and Maintainability

You are designing a Terraform infrastructure with multiple environments (dev, staging, prod). Which module composition pattern best supports reusability and environment-specific customization?

ACreate separate child modules for each environment with no shared code.
BCreate one root module per environment, each with duplicated child modules customized per environment.
CHardcode environment values inside child modules and call them without variables.
DUse a single root module with environment-specific variables passed to shared child modules.
Attempts:
2 left
💡 Hint

Consider how to avoid code duplication while allowing environment differences.