-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtfdestroy.sh
executable file
·49 lines (41 loc) · 1.15 KB
/
tfdestroy.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
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
TF_ENV=$(echo $TF_BACKEND | awk -F '.' '{print $1}' 2>&1)
TF_VARS=$(find . -type f -name "*.tfvars")
if [[ -f ${TF_ENV}.tfvars ]]; then
terraform destroy -var-file=${TF_ENV}.tfvars $@
elif [[ ! -z ${TF_VARS} ]]; then
TF_VARS=(${TF_VARS})
TF_VARS_len=${#TF_VARS[*]}
echo "--- Choose vars-file"
echo "-: Quit"
for ((i = 0; i < $TF_VARS_len; i++)); do
echo "$i: ${TF_VARS[$i]}"
done
echo
printf 'Selection: '
read choice
COLUMN=6
case $choice in
'' | *[!0-9\-]*)
clear
echo Invalid selection. Make a valid selection from the list above or press ctrl+c to exit
echo '-> Error: Not a number, and not "-"'
echo
break
;;
esac
in_range=false
while [ $in_range != true ]; do
if [[ $choice == '-' ]]; then
break
elif (($choice >= 0)) && (($choice <= (${TF_VARS_len}-1))); then
echo ${TF_VARS[choice]}
in_range=true
terraform destroy -var-file=${TF_VARS[choice]} $@
break
else
echo "!! Not a valid option"
break
fi
done
fi