Interview Prep/Terraform/Partial Applies, Version Mismatches and CI Failures

A CI pipeline applies `dev` successfully, then the `prod` stage applies `dev`'s plan file to prod state.

AdvancedTroubleshootingPartial Applies, Version Mismatches and CI Failures
Answer

Likely causes → Artifact name collision (tfplan used for both stages) or a missing -backend-config switch between stages. Terraform may error (Saved plan does not match the given state/stale) or, worse, apply with dev vars if the job re-plans with the wrong var file.

Diagnose → Check artifact names, the var file and backend config used in each stage's logs.

Fix → Stop the pipeline, inspect prod changes from the apply log, and correct with a proper prod plan.

Prevent → Name artifacts tfplan-<env>-<sha>, run each environment in its own directory/job with explicit -backend-config=backends/<env>.hcl and -var-file=env/<env>.tfvars, and print account ID + workspace before apply.

All Terraform questions

More on Partial Applies, Version Mismatches and CI Failures