-
Notifications
You must be signed in to change notification settings - Fork 7
/
destroy.sh
64 lines (53 loc) · 1.67 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Exit immediately if a command returns a non-zero status
set -e
# Printing script usage
program_name=$0
usage () {
echo "usage: $program_name { dev | prod | --google-env-file google-env-file.json --github-env-file github-env-file.json --backend-config-file backend.json }"
exit 1
}
dev=false
prod=false
# Parsing script params
while true; do
case "$1" in
--google-env-file ) google_env_file="$2"; shift 2 ;;
--github-env-file ) github_env_file="$2"; shift 2 ;;
--backend-config-file ) backend_config_file="$2"; shift 2 ;;
dev ) dev=true; shift 1 ;;
prod ) prod=true; shift 1;;
* ) break ;;
esac
done
if [ "$dev" = true ]; then
google_env_file="google-dev.tfvars.json"
github_env_file="github-dev.tfvars.json"
backend_config_file="backend-dev.tfvars.json"
fi
if [ "$prod" = true ]; then
google_env_file="google-prod.tfvars.json"
github_env_file="github-prod.tfvars.json"
backend_config_file="backend-prod.tfvars.json"
fi
# Checking script params
if [ -z "$google_env_file" ]; then
usage
fi
if [ -z "$github_env_file" ]; then
usage
fi
if [ -z "$backend_config_file" ]; then
usage
fi
google_env_file_path=$(realpath "$google_env_file")
github_env_file_path=$(realpath "$github_env_file")
backend_config_file_path=$(realpath "$backend_config_file")
project_root_path=$(realpath "$(dirname "$0")/..")
# cd project root directory
cd "$project_root_path"
# Destroy terraform
echo "Destroying infra using terraform..."
terraform init -backend-config="$backend_config_file_path"
terraform destroy -var-file="$google_env_file_path" -var-file="$github_env_file_path"
echo "Destroying infra using terraform done"