Skip to content

Commit

Permalink
feat: add ability to delete all stacks in happy environment
Browse files Browse the repository at this point in the history
  • Loading branch information
shitchcock committed Jun 27, 2024
1 parent a9e8928 commit 43ae40e
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions .github/actions/happy-cleanup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
description: The environment in which to delete stacks
required: true
default: rdev
all:
description: include every stack in the environment
required: false
default: false
time:
description: The longest period before a stack should be considered stale. Should be something like '2 weeks' or '1 day'
required: true
Expand Down Expand Up @@ -46,23 +50,28 @@ runs:
TFE_TOKEN: ${{ inputs.tfe_token }}
TIME: ${{inputs.time}}
EXCLUDE: ${{ inputs.exclude }}
ALL: ${{ inputs.all}}
HAPPY_OIDC_ID_TOKEN: ${{steps.idtoken.outputs.id_token}}
shell: bash
run: |
set -ue
set -o pipefail
date=`date +%Y-%m-%d'T'%H:%M'Z' -d "$TIME ago"`
list="happy list --aws-profile '' --output json --env $ENV"
force=""
if [[ ${ALL} ]]; then
list="happy list --all --aws-profile '' --output json --env $ENV"
force="--force"
fi
if [[ ! -z ${EXCLUDE} ]]; then
for i in $(happy list --aws-profile "" --output json --env $ENV | jq -r --arg date "$date" --arg exclude "$EXCLUDE" '.[] | select(.last_updated < $date) | select(any(.stack; contains($exclude))|not) | .stack'); do
for i in $("$list" | jq -r --arg date "$date" --arg exclude "$EXCLUDE" '.[] | select(.last_updated < $date) | select(any(.stack; contains($exclude))|not) | .stack'); do
echo "Deleting stack: $i"
happy delete $i --env $ENV --aws-profile ""
happy delete $i --env $ENV --aws-profile "" "$force"
done
exit
fi
for i in $(happy list --aws-profile "" --output json --env $ENV | jq -r --arg date "$date" '.[] | select(.last_updated < $date) | .stack'); do
for i in $("$list" | jq -r --arg date "$date" '.[] | select(.last_updated < $date) | .stack'); do
echo "Deleting stack: $i"
happy delete $i --env $ENV --aws-profile ""
done

happy delete $i --env $ENV --aws-profile "" "$force"
done

0 comments on commit 43ae40e

Please sign in to comment.