0
0
Terraformcloud~10 mins

Outputs for module communication in Terraform - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define an output variable in a Terraform module.

Terraform
output "instance_ip" {
  value = [1]
}
Drag options to blanks, or click blank then click option'
Aaws_instance.example.public_ip
Bvar.instance_ip
Cmodule.network.subnet_id
Dlocal.ip_address
Attempts:
3 left
💡 Hint
Common Mistakes
Referencing a variable instead of a resource attribute.
Using a module output inside the same module.
2fill in blank
medium

Complete the code to access an output from a child module in the root module.

Terraform
output "db_endpoint" {
  value = module.database.[1]
}
Drag options to blanks, or click blank then click option'
Adb_endpoint
Boutput_endpoint
Cendpoint_url
Ddatabase_url
Attempts:
3 left
💡 Hint
Common Mistakes
Guessing output names instead of matching the child module's output.
Using resource names instead of output names.
3fill in blank
hard

Fix the error in the output block to correctly expose the subnet ID from the module.

Terraform
output "subnet_id" {
  value = [1]
  description = "Subnet ID from the network module"
}
Drag options to blanks, or click blank then click option'
Alocal.subnet_id
Bvar.subnet_id
Cmodule.network.subnet_id
Daws_subnet.main.id
Attempts:
3 left
💡 Hint
Common Mistakes
Referencing a variable instead of a module output.
Using a resource directly inside an output in the root module.
4fill in blank
hard

Fill both blanks to define and access an output named 'bucket_name' from a module.

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

output "bucket_name" {
  value = module.storage.[1]
}

# Inside the storage module:
output "[2]" {
  value = aws_s3_bucket.main.bucket
}
Drag options to blanks, or click blank then click option'
Abucket_name
Bbucket_id
Cbucket
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the output inside and outside the module.
Referencing resource attributes directly outside the module.
5fill in blank
hard

Fill all three blanks to correctly define outputs in a module and access them in the root module.

Terraform
module "web" {
  source = "./modules/webserver"
}

output "web_ip" {
  value = module.web.[1]
}

# Inside the webserver module:
output "[2]" {
  value = aws_instance.web.public_ip
}

output "[3]" {
  value = aws_instance.web.id
}
Drag options to blanks, or click blank then click option'
Ainstance_ip
Bweb_ip
Cinstance_id
Dweb_id
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching output names between module and root.
Trying to access resource attributes directly outside the module.