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

In GitHub Actions, `terraform plan -detailed-exitcode` makes the job fail whenever there are changes.

BeginnerTroubleshootingPartial Applies, Version Mismatches and CI Failures
Answer

Likely causes → -detailed-exitcode returns 0 (no changes), 1 (error), 2 (changes present). Most CI systems treat any non-zero exit as failure.

Diagnose → The job log shows exit code 2.

Fix →

set +e
terraform plan -detailed-exitcode -out=tfplan -input=false
code=$?
set -e
if [ "$code" -eq 1 ]; then exit 1; fi
echo "has_changes=$([ "$code" -eq 2 ] && echo true || echo false)" >> "$GITHUB_OUTPUT"

Prevent → Wrap the logic in a shared script used by all pipelines.

All Terraform questions

More on Partial Applies, Version Mismatches and CI Failures