From 62a66eef78e1543742cc8fabf333a1abddc00d37 Mon Sep 17 00:00:00 2001 From: Yordan Ibishev Date: Wed, 18 May 2022 13:47:46 +0100 Subject: [PATCH] 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 --- dist/index1.js | 12 +++++++++--- wrapper/terraform.js | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/dist/index1.js b/dist/index1.js index 976a901..6755f84 100755 --- a/dist/index1.js +++ b/dist/index1.js @@ -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}.`); })(); })(); diff --git a/wrapper/terraform.js b/wrapper/terraform.js index 68ee962..b0311af 100755 --- a/wrapper/terraform.js +++ b/wrapper/terraform.js @@ -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}.`); })();