hashicorp / setup-terraform

Sets up Terraform CLI in your GitHub Actions workflow.
https://developer.hashicorp.com/terraform/tutorials/automation/github-actions
Mozilla Public License 2.0
1.34k stars 235 forks source link

Terraform Plan Exitcode Not 2 as expected when there's updates. #417

Open Dipak-Mistry-WTW opened 2 months ago

Dipak-Mistry-WTW commented 2 months ago

When using Githust hosted runner the exitcode is set to 0 from Terraform plan step even when there are updates. At the end of the plan step I see:

##[debug]Saved the plan to: dev.tfplan
##[debug]
##[debug]To perform exactly these actions, run the following command to apply:
##[debug]    terraform apply "dev.tfplan"
##[debug]Releasing state lock. This may take a few moments...
##[debug]
##[debug]Set output stderr = 
##[debug]Set output exitcode = 2
##[debug]Set output exitcode = 0
##[debug]Finishing: Terraform Plan

Then in the Complete Job step I see:

##[debug]Starting: Complete job
Evaluate and set job outputs
##[debug]Evaluating: steps.tf-plan.outputs.exitcode
##[debug]Evaluating Index:
##[debug]..Evaluating Index:
##[debug]....Evaluating Index:
##[debug]......Evaluating steps:
##[debug]......=> Object
##[debug]......Evaluating String:
##[debug]......=> 'tf-plan'
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'outputs'
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'exitcode'
##[debug]=> '0'
##[debug]Result: '0'
Set output 'tfplanExitCode'
Cleaning up orphan processes
##[debug]Finishing: Complete job

The next job needs exitcode of 2 to run the terraform apply step.

np5 commented 2 weeks ago

The wrapper that is installed by default masks the exit code. You can use the action with the terraform_wrapper: false option, or you can change your tests to check for the outputs that the wrapper is already setting up.