0
0
Terraformcloud~20 mins

Module outputs in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Module Output Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Understanding Terraform module output usage
Given a Terraform root module that calls a child module which defines an output named instance_ip, what will be the value of module.webserver.instance_ip after applying the configuration?
Terraform
module "webserver" {
  source = "./modules/aws_instance"
  instance_count = 1
}

output "webserver_ip" {
  value = module.webserver.instance_ip
}
AThe public IP address of the AWS instance created by the child module.
BThe private IP address of the AWS instance created by the child module.
CAn error because <code>instance_ip</code> is not defined in the root module.
DNull because outputs cannot be accessed from modules.
Attempts:
2 left
💡 Hint
Remember that outputs defined in child modules can be accessed via module.. in the root module.
Configuration
intermediate
2:00remaining
Correctly referencing outputs from a nested module
You have a Terraform module db that outputs db_endpoint. How do you correctly expose this output in the root module so it can be used elsewhere?
Terraform
module "db" {
  source = "./modules/database"
}

output "database_endpoint" {
  value = ???
}
Adb.db_endpoint
Bmodule.database.db_endpoint
Coutput.db_endpoint
Dmodule.db.db_endpoint
Attempts:
2 left
💡 Hint
Outputs from modules are accessed using module...
Architecture
advanced
2:00remaining
Impact of missing outputs in Terraform modules
If a Terraform child module creates resources but does not define any outputs, what is the impact on the root module's ability to use information from those resources?
ATerraform will throw an error during plan because outputs are missing.
BThe root module can still access all resource attributes automatically.
CThe root module cannot access any information about the child module's resources directly.
DThe root module can access outputs only if the child module has variables defined.
Attempts:
2 left
💡 Hint
Think about how Terraform shares data between modules.
security
advanced
2:00remaining
Security considerations when exposing sensitive outputs from Terraform modules
A Terraform module outputs a sensitive value like a database password using sensitive = true. What happens if the root module references this output without marking it sensitive?
ATerraform will mask the value in CLI output and state files automatically.
BThe root module must explicitly mark the output as sensitive to keep it hidden.
CTerraform will refuse to apply the configuration due to sensitivity mismatch.
DThe sensitive value will be shown in CLI output and logs, risking exposure.
Attempts:
2 left
💡 Hint
Consider how Terraform handles sensitive outputs across module boundaries.
Best Practice
expert
2:00remaining
Best practice for outputting multiple values from a Terraform module
You want to output multiple related values from a Terraform module, such as instance ID, public IP, and private IP. Which approach is best to keep outputs clean and manageable?
ACombine all values into a single map output with keys for each value.
BDefine separate outputs for each value: <code>instance_id</code>, <code>public_ip</code>, <code>private_ip</code>.
COutput a list containing all values in order without keys.
DDo not output these values; instead, access resources directly from the root module.
Attempts:
2 left
💡 Hint
Think about how to group related data for easier consumption.