Skip to content

Commit

Permalink
Support detailed exit codes. (#125)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
dannyibishev and jpogran committed May 18, 2022
1 parent d6a45b7 commit 62a66ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions dist/index1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3069,10 +3069,16 @@ 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}.`);
})();

})();
Expand Down
12 changes: 9 additions & 3 deletions wrapper/terraform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`);
})();

0 comments on commit 62a66ee

Please sign in to comment.