0
0
Terraformcloud~20 mins

Creating a child module in Terraform - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Child Module Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding child module source paths

You have a Terraform root module and want to include a child module located in a folder named modules/network. Which source value correctly references this child module?

A"./modules/network"
B"network/modules"
C"../modules/network"
D"modules/network/"
Attempts:
2 left
💡 Hint

Think about the path relative to the root module where you call the child module.

Configuration
intermediate
2:00remaining
Passing variables to a child module

You want to pass a variable named region with value "us-west-2" to a child module. Which is the correct way to do this in the root module?

Terraform
module "child" {
  source = "./modules/child"
  // pass region here
}
Avariables.region = "us-west-2"
Bvar.region = "us-west-2"
Cregion = "us-west-2"
Dinput.region = "us-west-2"
Attempts:
2 left
💡 Hint

Variables are passed by naming them directly inside the module block.

Architecture
advanced
2:00remaining
Module output usage in root module

A child module outputs a value named subnet_id. How do you correctly reference this output in the root module?

Terraform
output "subnet_id" {
  value = module.child.subnet_id
}
Amodule.child.subnet_id
Bchild.subnet_id
Cmodule.subnet_id.child
Doutput.child.subnet_id
Attempts:
2 left
💡 Hint

Outputs from child modules are accessed using module...

security
advanced
2:00remaining
Avoiding sensitive data exposure in child modules

You have a child module that outputs a sensitive value like a password. What is the best way to prevent this sensitive output from showing in the root module's plan or apply output?

AEncrypt the output value manually before output
BDo not declare the output in the child module
CSet <code>private = true</code> on the output
DMark the output as <code>sensitive = true</code> in the child module
Attempts:
2 left
💡 Hint

Terraform has a built-in way to mark outputs as sensitive.

service_behavior
expert
3:00remaining
Effect of changing child module source on Terraform state

You update the source path of a child module in your root module to point to a different folder with a different resource configuration. What happens when you run terraform apply?

ATerraform will automatically migrate the state from old to new module resources
BTerraform will treat the new module as a new set of resources and try to create them, leaving old resources orphaned
CTerraform will delete all old resources before creating new ones
DTerraform will throw an error and refuse to apply
Attempts:
2 left
💡 Hint

Think about how Terraform tracks resources by module source paths.