Practical infrastructure challenge

Terraform Configuration Debugging Challenge

Diagnose Terraform configuration errors, repair resource references and iteration, and distinguish configuration validation from run-specific checks.

1. Inspect the broken configuration

Service catalog

A team wants one built-in terraform_data instance per distinct service name, with an output for the catalog service. This original example has two deliberate defects. No cloud account or external provider is needed.

variable "services" {
  type    = list(string)
  default = ["catalog", "billing"]
}

resource "terraform_data" "service" {
  for_each = var.services
  input    = each.key
}

output "catalog" {
  value = terraform_data.services["catalog"].input
}
Inspect the scenario data
{
  "file": "main.tf",
  "intent": "One terraform_data instance per distinct service name; output the catalog instance's input.",
  "configuration": "variable \"services\" {\n  type    = list(string)\n  default = [\"catalog\", \"billing\"]\n}\n\nresource \"terraform_data\" \"service\" {\n  for_each = var.services\n  input    = each.key\n}\n\noutput \"catalog\" {\n  value = terraform_data.services[\"catalog\"].input\n}"
}

2. Diagnose the configuration

Loading the practice questions...

3. Repair the configuration

Write a corrected version of main.tf. Keep the variable type and defaults, create one instance per unique service name, and return the catalog instance's input. Preserve the resource label and output name.

main.tfTerraform ยท HCL
Need a conceptual hint?

Compare the collection type expected by for_each with the declared variable type. Compare the resource label and instance key with the output reference.

Compare a reference example after attempting
variable "services" {
  type    = list(string)
  default = ["catalog", "billing"]
}

resource "terraform_data" "service" {
  for_each = toset(var.services)
  input    = each.key
}

output "catalog" {
  value = terraform_data.service["catalog"].input
}

Compare the collection conversion and resource address against your draft. The editor provides HCL self-comparison rather than native Terraform execution.

4. Explain your debugging decision

Explain the difference between formatting, validation and planning. Describe why stable instance keys matter and why a statically invalid resource reference cannot be repaired using try.

Continue your learning

Explore Terraform Foundations, Plan Review Challenge, State and Drift Challenge and learning methodology.

Technical references