Support detailed exit codes. (#125)

* feat(action): Support detailed exit codes. 

This should allow plans to succeed using the terraform_wrapper functionality whenever an exit code of 2 is returned.
https://www.terraform.io/docs/cli/commands/plan.html#detailed-exitcode

- This is useful for adding custom steps in our GitHub action workflows.
- Not a Javascript developer so Im not sure how valid the OR condition is.

Co-authored-by: James Pogran <jpogran@outlook.com>
This commit is contained in:
Yordan Ibishev 2022-05-18 13:47:46 +01:00 committed by GitHub
parent d6a45b7634
commit 62a66eef78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View file

@ -41,8 +41,14 @@ async function checkTerraform () {
core.setOutput('stderr', stderr.contents);
core.setOutput('exitcode', exitCode.toString(10));
// A non-zero exitCode is considered an error
if (exitCode !== 0) {
core.setFailed(`Terraform exited with code ${exitCode}.`);
if (exitCode === 0 || exitCode === 2) {
// A exitCode of 0 is considered a success
// An exitCode of 2 may be returned when the '-detailed-exitcode' option
// is passed to plan. This denotes Success with non-empty
// diff (changes present).
return;
}
// A non-zero exitCode is considered an error
core.setFailed(`Terraform exited with code ${exitCode}.`);
})();