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

A module output is `null` in the root although the resource exists.

IntermediateTroubleshootingModules, Variables, Sensitive Values and Workspaces
Answer

Likely causes → The output uses try(aws_x.this[0].id, null) and the resource has a different index/key; or the resource is conditional (count = var.create ? 1 : 0) and create is false for this call.

Diagnose → terraform state list | grep module.app, terraform console → module.app.

Fix → Correct the output expression (one(aws_x.this[*].id)), or set the create flag.

Prevent → Avoid try() that hides real errors in outputs; return explicit nulls only for genuinely optional resources.

All Terraform questions Roadmap: Terraform

More on Modules, Variables, Sensitive Values and Workspaces