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

A `count = terraform.workspace == "prod" ? 3 : 1` setup created 3 NAT gateways in staging.

IntermediateTroubleshootingModules, Variables, Sensitive Values and Workspaces
Answer

Likely causes → The CI job for staging ran in a workspace named prod (or the comparison uses a name that doesn't match, like production). Logic tied to terraform.workspace breaks silently.

Diagnose → terraform workspace show in the job; compare names exactly.

Fix → Drive sizing from per-env tfvars (nat_gateway_count = 1), not from the workspace name.

Prevent → Use terraform.workspace only for naming; put behaviour differences in variables.

All Terraform questions Roadmap: Terraform

More on Modules, Variables, Sensitive Values and Workspaces