diff --git a/action.yml b/action.yml index dadd1d537..3275b6f7c 100644 --- a/action.yml +++ b/action.yml @@ -266,12 +266,6 @@ runs: bucketName: ${{ inputs.terraform-state-bucket }} failOnMissingPlan: "false" - - if: ${{ steps.atmos-plan.outputs.changes == 'true' }} - shell: bash - run: |- - cat ${{ steps.vars.outputs.plan_file }}.stored - - - name: Compare Current and Stored PLANFILEs if: ${{ steps.atmos-plan.outputs.changes == 'true' }} id: new-plan @@ -282,21 +276,30 @@ runs: PLAN_FILE_STORED="${{ steps.vars.outputs.plan_file }}.stored" NEW_PLAN_FOUND=false - if [ -f "$PLAN_FILE_STORED" ]; then + if [ -f "$PLAN_FILE_STORED" ]; then + set +e terraform show -json "$PLAN_FILE_STORED" > "$PLAN_FILE_STORED.json" - - # sort and remove timestamp - jq 'if has("relevant_attributes") then .relevant_attributes |= sort_by(.resource, .attribute) else . end' "$PLAN_FILE.json" | jq 'del(.timestamp)' > current.json - jq 'if has("relevant_attributes") then .relevant_attributes |= sort_by(.resource, .attribute) else . end' "$PLAN_FILE_STORED.json" | jq 'del(.timestamp)' > stored.json - - # calculate checksums of stored and current plans - MD5_CURRENT=$(md5sum current.json | awk '{ print $1 }') - MD5_STORED=$(md5sum stored.json | awk '{ print $1 }') - if [ "$MD5_CURRENT" == "$MD5_STORED" ]; then - echo "Current plan is equal to stored plan" + TERRAFORM_RESULT=$? + + set -e + + if [[ "${TERRAFORM_RESULT}" == "0" ]]; then + # sort and remove timestamp + jq 'if has("relevant_attributes") then .relevant_attributes |= sort_by(.resource, .attribute) else . end' "$PLAN_FILE.json" | jq 'del(.timestamp)' > current.json + jq 'if has("relevant_attributes") then .relevant_attributes |= sort_by(.resource, .attribute) else . end' "$PLAN_FILE_STORED.json" | jq 'del(.timestamp)' > stored.json + + # calculate checksums of stored and current plans + MD5_CURRENT=$(md5sum current.json | awk '{ print $1 }') + MD5_STORED=$(md5sum stored.json | awk '{ print $1 }') + + if [ "$MD5_CURRENT" == "$MD5_STORED" ]; then + echo "Current plan is equal to stored plan" + else + echo "Current plan is different from stored plan" + NEW_PLAN_FOUND=true + fi else - echo "Current plan is different from stored plan" NEW_PLAN_FOUND=true fi else