Skip to content

Commit 62a66ee

Browse files
yordaa-mejpogran
andauthored
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 <[email protected]>
1 parent d6a45b7 commit 62a66ee

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

dist/index1.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,10 +3069,16 @@ async function checkTerraform () {
30693069
core.setOutput('stderr', stderr.contents);
30703070
core.setOutput('exitcode', exitCode.toString(10));
30713071

3072-
// A non-zero exitCode is considered an error
3073-
if (exitCode !== 0) {
3074-
core.setFailed(`Terraform exited with code ${exitCode}.`);
3072+
if (exitCode === 0 || exitCode === 2) {
3073+
// A exitCode of 0 is considered a success
3074+
// An exitCode of 2 may be returned when the '-detailed-exitcode' option
3075+
// is passed to plan. This denotes Success with non-empty
3076+
// diff (changes present).
3077+
return;
30753078
}
3079+
3080+
// A non-zero exitCode is considered an error
3081+
core.setFailed(`Terraform exited with code ${exitCode}.`);
30763082
})();
30773083

30783084
})();

wrapper/terraform.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ async function checkTerraform () {
4141
core.setOutput('stderr', stderr.contents);
4242
core.setOutput('exitcode', exitCode.toString(10));
4343

44-
// A non-zero exitCode is considered an error
45-
if (exitCode !== 0) {
46-
core.setFailed(`Terraform exited with code ${exitCode}.`);
44+
if (exitCode === 0 || exitCode === 2) {
45+
// A exitCode of 0 is considered a success
46+
// An exitCode of 2 may be returned when the '-detailed-exitcode' option
47+
// is passed to plan. This denotes Success with non-empty
48+
// diff (changes present).
49+
return;
4750
}
51+
52+
// A non-zero exitCode is considered an error
53+
core.setFailed(`Terraform exited with code ${exitCode}.`);
4854
})();

0 commit comments

Comments
 (0)