fix: Preserve Terraform exit code in plan step #13
Reference in New Issue
Block a user
Delete Branch "fix/terraform-plan-exitcode"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The Gitea Actions workflows were incorrectly capturing the exit code from the
terraform plancommand. The command was using| teeto display the output while saving it to a file, but this caused the$?variable to capture the exit code oftee(which is always 0) instead ofterraform plan. This meant:terraform-deploy.yml: Thehas_changesoutput was alwaysfalse, preventing theapplyjob from running even when changes were detectedterraform-pr.yml: Theexitcodeoutput was always0, making it impossible to distinguish between no changes and changes detectedSolution
Modified both workflow files to:
teewith a direct redirect to file:> plan_output.txt 2>&1cat plan_output.txtcommand to display the output in the logsThis preserves Terraform's exit code (0 for no changes, 2 for changes detected, 1 for errors) so the workflows can properly determine if changes exist and proceed with deployment.
Testing
The changes maintain the same functionality:
plan_output.txtfor later usecatterraform plancommandPull request closed