Bird
Raised Fist0
Terraformcloud~20 mins

Module outputs in Terraform - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of output blocks in a Terraform module?
easy
A. To share information from inside the module to the outside
B. To define variables that the module accepts
C. To create resources inside the module
D. To delete resources after deployment

Solution

  1. Step 1: Understand the role of output blocks

    Output blocks are used to expose values from a module so other parts of the Terraform configuration can use them.
  2. Step 2: Differentiate outputs from variables and resources

    Variables are inputs to modules, resources create infrastructure, outputs share info outwards.
  3. Final Answer:

    To share information from inside the module to the outside -> Option A
  4. Quick Check:

    Outputs = share info outside module [OK]
Hint: Outputs pass info out of modules, variables bring info in [OK]
Common Mistakes:
  • Confusing outputs with variables
  • Thinking outputs create resources
  • Assuming outputs delete resources
2. Which of the following is the correct syntax to define an output named instance_ip in a Terraform module?
easy
A. output "instance_ip" : aws_instance.example.public_ip
B. output instance_ip = aws_instance.example.public_ip
C. output "instance_ip" { value = aws_instance.example.public_ip }
D. output { instance_ip = aws_instance.example.public_ip }

Solution

  1. Step 1: Recall Terraform output block syntax

    Outputs use the keyword output followed by the name in quotes, then a block with value = ....
  2. Step 2: Match syntax to options

    output "instance_ip" { value = aws_instance.example.public_ip } matches the correct syntax: output "name" { value = ... }.
  3. Final Answer:

    output "instance_ip" { value = aws_instance.example.public_ip } -> Option C
  4. Quick Check:

    Output block = output "name" { value = ... } [OK]
Hint: Outputs need quotes and value assignment inside braces [OK]
Common Mistakes:
  • Missing quotes around output name
  • Using equals sign outside block
  • Incorrect colon or braces placement
3. Given this module output block:
output "bucket_name" {
  value = aws_s3_bucket.my_bucket.id
}

And this root module code:
module "storage" {
  source = "./modules/s3"
}

output "name" {
  value = module.storage.bucket_name
}

What will be the value of the root module's name output after applying?
medium
A. The name of the S3 bucket resource type
B. Null because the module output is not defined
C. An error because outputs cannot be nested
D. The ID of the S3 bucket created by the module

Solution

  1. Step 1: Understand module output propagation

    The module outputs the bucket's ID as bucket_name. The root module accesses it via module.storage.bucket_name.
  2. Step 2: Confirm root output value

    The root output name simply passes through the module's output value, so it will be the bucket ID.
  3. Final Answer:

    The ID of the S3 bucket created by the module -> Option D
  4. Quick Check:

    Root output = module output value [OK]
Hint: Root outputs can reference module outputs directly [OK]
Common Mistakes:
  • Thinking outputs cannot be nested or chained
  • Confusing bucket ID with resource type name
  • Assuming output is null if not explicitly set in root
4. You have this output block inside a module:
output "subnet_id" {
  value = aws_subnet.example
}

Why is this incorrect for outputting the subnet ID?
medium
A. The output value should reference a specific attribute, like aws_subnet.example.id
B. Output blocks cannot reference resources directly
C. The output name cannot be "subnet_id"
D. The module source path is missing

Solution

  1. Step 1: Check output value correctness

    To output the subnet ID, the value must reference a specific attribute like aws_subnet.example.id, not the whole resource object.
  2. Step 2: Identify correct attribute to output

    For subnet ID, use aws_subnet.example.id instead of the resource itself.
  3. Final Answer:

    The output value should reference a specific attribute, like aws_subnet.example.id -> Option A
  4. Quick Check:

    Output value = resource attribute, not resource object [OK]
Hint: Always output resource attributes, not whole resources [OK]
Common Mistakes:
  • Outputting entire resource instead of attribute
  • Wrong output block name
  • Ignoring module source configuration
5. You want to create a module that outputs a list of public IPs from multiple instances it creates. Which output block correctly returns this list?
hard
A. output "public_ips" { value = aws_instance.example[0].public_ip }
B. output "public_ips" { value = [for inst in aws_instance.example : inst.public_ip] }
C. output "public_ips" { value = aws_instance.example[*].id }
D. output "public_ips" { value = aws_instance.example }

Solution

  1. Step 1: Understand how to output multiple values

    When multiple instances exist, use a for-expression to collect their public IPs into a list.
  2. Step 2: Match correct syntax for list output

    output "public_ips" { value = [for inst in aws_instance.example : inst.public_ip] } uses a for-expression to extract public_ip from each instance correctly.
  3. Final Answer:

    output "public_ips" { value = [for inst in aws_instance.example : inst.public_ip] } -> Option B
  4. Quick Check:

    Use for-expression to output lists from multiple resources [OK]
Hint: Use for-expressions to gather attributes from multiple resources [OK]
Common Mistakes:
  • Outputting single attribute from multiple instances without list
  • Using wrong attribute like id instead of public_ip
  • Outputting entire resource object
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard