Skip to content

Commit

Permalink
Further testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mikereiddigital committed Jan 23, 2025
1 parent 82c494b commit c3ee997
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reusable_terraform_plan_apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ jobs:
id: get_destroy_count
env:
DESTROY_THRESHOLD: ${{ env.TF_DESTROY_THRESHOLD }}
PLAN_SUMMARY: ${{ steps.show.outputs.plan_summary }}
PLAN_DESTROY_CHECK: ${{ steps.show.outputs.plan_destroy_check }}
run: |
bash scripts/get-terraform-destroy-count.sh
Expand Down
8 changes: 4 additions & 4 deletions scripts/get-terraform-destroy-count.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ set -e
# It also runs some checks to ensure that the values for the count and the threshold are valid.

# Checks that PLAN_SUMMARY is set. Without this the script will fail so we force an exit.
if [ -z "$PLAN_SUMMARY" ]; then
echo "PLAN_SUMMARY is not set"
if [ -z "$PLAN_DESTROY_CHECK" ]; then
echo "PLAN_DESTROY_CHECK is not set"
exit 1
fi

destroy_count=$(echo "$PLAN_SUMMARY" | grep -oE 'Plan: [0-9]+ to add, [0-9]+ to change, [0-9]+ to destroy.' | awk '{print $8}')
destroy_count=$(echo "$PLAN_DESTROY_CHECK" | grep -oE 'Plan: [0-9]+ to add, [0-9]+ to change, [0-9]+ to destroy.' | awk '{print $8}')

echo "destroy_threshold=$DESTROY_THRESHOLD"
echo "destroy_count=$destroy_count"

if echo "$PLAN_SUMMARY" | grep -q "No changes. Your infrastructure matches the configuration."; then
if echo "$PLAN_DESTROY_CHECK" | grep -q "No changes. Your infrastructure matches the configuration."; then
echo "No changes. Your infrastructure matches the configuration."
destroy_count=0
exit 0
Expand Down
4 changes: 3 additions & 1 deletion scripts/terraform-plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ else
echo "$plan_output" # Output full redacted plan to stdout (GitHub Actions logs)
fi

echo "plan_summary=$plan_summary" >> "$GITHUB_OUTPUT"
echo "plan_destroy_check=$plan_summary" >> "$GITHUB_OUTPUT"

echo "summary<<EOF" >> $GITHUB_OUTPUT
echo "$plan_summary" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

0 comments on commit c3ee997

Please sign in to comment.