Skip to content

Commit

Permalink
Test plan
Browse files Browse the repository at this point in the history
  • Loading branch information
goruha committed Nov 17, 2023
1 parent 527ecb1 commit c10c833
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c10c833

Please sign in to comment.