Challenge - 5 Problems
Terraform Module Output Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate2:00remaining
What is the output value of the root module after applying this Terraform configuration?
Given a root module that calls a child module which outputs a value, what will be the value of
module.child.output_value in the root module?Terraform
module "child" { source = "./child_module" input_var = "hello" } output "child_output" { value = module.child.output_value } # child_module/main.tf variable "input_var" {} output "output_value" { value = "${var.input_var}-world" }
Attempts:
2 left
💡 Hint
Remember that module outputs can be accessed in the root module using
module.. .✗ Incorrect
The child module outputs the value by appending '-world' to the input variable 'hello'. The root module accesses this output via
module.child.output_value, so the final output is 'hello-world'.❓ Configuration
intermediate2:00remaining
Which option correctly defines an output in a Terraform module to expose a resource attribute?
You want to expose the ID of an AWS EC2 instance created inside a module. Which output block correctly achieves this?
Terraform
resource "aws_instance" "example" { ami = "ami-123456" instance_type = "t2.micro" } # Define output here
Attempts:
2 left
💡 Hint
Resource attributes are accessed by their exact attribute names, not by index or the whole resource.
✗ Incorrect
The correct attribute for the instance ID is 'id'. Option A correctly references it. Option A uses a non-existent attribute 'instance_id'. Option A tries to index a non-list resource. Option A returns the whole resource, which is invalid for output value.
❓ Architecture
advanced2:00remaining
How can you pass a computed value from one module to another in Terraform?
You have two modules: Module A creates a VPC and outputs its ID. Module B needs the VPC ID to create subnets. How should you connect these modules in the root module?
Terraform
module "vpc" { source = "./vpc_module" } module "subnet" { source = "./subnet_module" vpc_id = ??? }
Attempts:
2 left
💡 Hint
Modules expose outputs that can be referenced by other modules in the root module.
✗ Incorrect
Module outputs are accessed using
module.. . So to pass the VPC ID from Module A to Module B, you assign vpc_id = module.vpc.vpc_id_output in the root module.❓ security
advanced2:00remaining
What is a security risk when exposing sensitive data via Terraform module outputs?
You have a module output that exposes a database password. What is the main risk and how can you mitigate it?
Attempts:
2 left
💡 Hint
Terraform state files store outputs and can be read if not protected.
✗ Incorrect
Terraform state files store output values in plain text by default. Marking outputs as sensitive hides them from CLI output and reduces accidental exposure. This is the recommended mitigation.
✅ Best Practice
expert2:00remaining
What is the best practice for managing outputs when a module is used multiple times with different configurations?
You use the same module twice to create two different environments (dev and prod). How should you handle outputs to avoid conflicts and confusion?
Attempts:
2 left
💡 Hint
Terraform distinguishes module instances by their names in the root module.
✗ Incorrect
Each module instance should have a unique name in the root module. Outputs are accessed via these names, preventing conflicts and making it clear which environment's output is referenced.