Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Commit 979773f

Browse files
authored
Merge pull request #73 from philippschulte/add-changes_present-output-variable-to-plan-action
Add changes-present output variable to plan action
2 parents 311e58f + 860f9ce commit 979773f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

plan/entrypoint.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,22 @@ if [[ ! -z "$TF_ACTION_WORKSPACE" ]] && [[ "$TF_ACTION_WORKSPACE" != "default" ]
4444
fi
4545

4646
set +e
47-
OUTPUT=$(sh -c "TF_IN_AUTOMATION=true terraform plan -input=false $*" 2>&1)
47+
OUTPUT=$(sh -c "TF_IN_AUTOMATION=true terraform plan -detailed-exitcode -input=false $*" 2>&1)
4848
SUCCESS=$?
4949
echo "$OUTPUT"
5050
set -e
5151

52+
# Detailed exit codes of the plan command include:
53+
# - 0 = Succeeded with empty diff (no changes)
54+
# - 1 = Error
55+
# - 2 = Succeeded with non-empty diff (changes present)
56+
CHANGES_PRESENT=false
57+
if [ $SUCCESS -eq 2 ]; then
58+
CHANGES_PRESENT=true
59+
SUCCESS=0
60+
fi
61+
echo ::set-output name=changes-present::$CHANGES_PRESENT
62+
5263
if [ "$TF_ACTION_COMMENT" = "1" ] || [ "$TF_ACTION_COMMENT" = "false" ]; then
5364
exit $SUCCESS
5465
fi

0 commit comments

Comments
 (0)