Interview Prep/Terraform/Modules, Variables, Sensitive Values and Workspaces

A module with `count = var.enabled ? 1 : 0` breaks every reference with `Missing resource instance key` after you added the count.

IntermediateTroubleshootingModules, Variables, Sensitive Values and Workspaces
Answer

Likely causes → Module instances now have keys (module.cache[0]); references and state addresses changed.

Diagnose → The plan wants to destroy module.cache.* and create module.cache[0].*.

Fix →

moved {
  from = module.cache
  to   = module.cache[0]
}

Update references to module.cache[0].endpoint or one(module.cache[*].endpoint).

Prevent → Add moved blocks whenever you add count/for_each to an existing module or resource.

All Terraform questions Roadmap: Terraform

More on Modules, Variables, Sensitive Values and Workspaces