Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show diff when approved and current plans differ, remove state lock message from plan #567

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions terraform-v2/apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ include github.py

EOF

cat >/tmp/cmp.py <<"EOF"
include cmp.py

EOF

cat >/tmp/comment_util.py <<"EOF"
include comment_util.py

Expand Down Expand Up @@ -88,6 +83,11 @@ fi

set -e

function sanitise_plan() {
local plan="$1"
echo "$plan" | sed -E '/Releasing state lock. This may take a few moments\.\.\./d' | awk '{gsub(/^[[:space:]]*~ latest_restorable_time[[:space:]]*=.*$/,"")};1'
}


if [[ "<< parameters.auto_approve >>" == "true" || $TF_EXIT -eq 0 ]]; then
echo "Automatically approving plan"
Expand All @@ -99,10 +99,25 @@ else
exit 1
fi

if python3 /tmp/cmp.py plan.txt approved-plan.txt; then
set +x

plan=$(cat "plan.txt")
approved_plan=$(cat "approved-plan.txt")

sanitised_plan=$(sanitise_plan "$plan")
sanitised_approved_plan=$(sanitise_plan "$approved_plan")

sanitised_plan_file=$(mktemp)
sanitised_approved_plan_file=$(mktemp)
echo "$sanitised_plan" > "$sanitised_plan_file"
echo "$sanitised_approved_plan" > "$sanitised_approved_plan_file"

# run diff on temporary files
if diff_output=$(diff "$sanitised_plan_file" "$sanitised_approved_plan_file"); then
apply
else
update_status "Plan not applied in CircleCI Job [${CIRCLE_JOB}](${CIRCLE_BUILD_URL}) (Plan has changed)"
echo "$diff_output"
exit 1
fi
fi
24 changes: 0 additions & 24 deletions terraform-v2/cmp.py

This file was deleted.