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

`terraform apply` in a terminal ran against prod because `terraform workspace show` said `prod`, though you selected `dev` earlier.

IntermediateTroubleshootingModules, Variables, Sensitive Values and Workspaces
Answer

Likely causes → TF_WORKSPACE=prod is exported in the shell (overrides workspace select), or the .terraform/environment file was changed by another command in the same directory.

Diagnose → echo $TF_WORKSPACE; cat .terraform/environment

Fix → unset TF_WORKSPACE; re-select dev. Review what was applied to prod and revert via a proper plan if needed.

Prevent → Show workspace and AWS account in your prompt; prefer separate directories/backends per environment for prod; protect prod with separate credentials that a dev shell doesn't have.

All Terraform questions Roadmap: Terraform

More on Modules, Variables, Sensitive Values and Workspaces