forked from IBM/automation-turbonomic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdestroy.sh
executable file
·39 lines (33 loc) · 943 Bytes
/
destroy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /bin/bash
RESOURCE_FILTER="$1"
echo ""
echo "Listing current state"
terraform state list
if [[ -n "${RESOURCE_FILTER}" ]]; then
echo ""
echo "Collecting resources to destroy using filter: ${RESOURCE_FILTER}"
RESOURCE_LIST=""
while read -r resource; do
echo " Adding $resource to destroy targets"
RESOURCE_LIST="$RESOURCE_LIST -target=$resource"
done < <(terraform state list | grep -E "${RESOURCE_FILTER}")
else
echo ""
echo "Collecting resources to destroy"
RESOURCE_LIST=""
while read -r resource; do
echo " Adding $resource to destroy targets"
RESOURCE_LIST="$RESOURCE_LIST -target=$resource"
done < <(terraform state list)
fi
if [[ -n "$RESOURCE_LIST" ]]; then
echo ""
echo "Planning destroy"
terragrunt plan -destroy ${RESOURCE_LIST} -out=destroy.plan
echo ""
echo "Destroying resources"
terrgrunt apply -auto-approve destroy.plan
else
echo ""
echo "Nothing to destroy!!"
fi