-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdelete_stacks.sh
More file actions
executable file
·22 lines (19 loc) · 926 Bytes
/
delete_stacks.sh
File metadata and controls
executable file
·22 lines (19 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env bash
ACTIVE_STACKS=$(aws cloudformation list-stacks | jq -r '.StackSummaries[] | select ( .StackStatus != "DELETE_COMPLETE" ) | select( .StackName | capture("^fhir-validator-pr-(sandbox-)?(\\d+)$") ) | .StackName ')
mapfile -t ACTIVE_STACKS_ARRAY <<< "$ACTIVE_STACKS"
for i in "${ACTIVE_STACKS_ARRAY[@]}"
do
echo "Checking if stack $i has open pull request"
PULL_REQUEST=${i//fhir-validator-pr-/}
PULL_REQUEST=${PULL_REQUEST//sandbox-/}
echo "Checking pull request id ${PULL_REQUEST}"
URL="https://api.github.com/repos/NHSDigital/eps-FHIR-validator-lambda/pulls/${PULL_REQUEST}"
RESPONSE=$(curl "${URL}" 2>/dev/null)
STATE=$(echo "${RESPONSE}" | jq -r .state)
if [ "$STATE" == "closed" ]; then
echo "** going to delete stack $i as state is ${STATE} **"
aws cloudformation delete-stack --stack-name "${i}"
else
echo "not going to delete stack $i as state is ${STATE}"
fi
done