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.
More on Partial Applies, Version Mismatches and CI Failures
An apply failed halfway: 14 resources created, then `Error: creating RDS DB Instance ... InvalidParameterCombination`. What state are you in?Beginner`Error: Saved plan is stale` — `The given plan file can no longer be applied because the state was changed by another operation after the plan was created.`IntermediateApply job fails: `Failed to read plan from plan file` — `The given plan file was created by Terraform v1.9.5, but this is v1.9.8.`Intermediate`Error: Unsupported Terraform Core version` — `This configuration does not support Terraform version 1.5.7.`BeginnerA teammate with Terraform 1.10 applied; now your 1.6 gets `state snapshot was created by Terraform v1.10.0, which is newer than current v1.6.6; upgrade to Terraform v1.10.0 or greater to work with this state`.Intermediate`Error: Resource instance managed by newer provider version` — `The current state of aws_instance.web was created by a newer provider version than is currently selected.`Intermediate