-
Notifications
You must be signed in to change notification settings - Fork 4
/
destroy.sh
executable file
·36 lines (28 loc) · 925 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
#!/bin/bash
set -e
environment=$1
ENVIRONMENT=$1
DIR_ABS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SYSTEM=$(basename $DIR_ABS)
if [ -z $ENVIRONMENT ]; then
echo "No environment set. Please use 'development', 'stagaing', 'testing' or 'production'"
exit 1
fi
if [ "$ENVIRONMENT" != development ] \
&& [ "$ENVIRONMENT" != testing ] \
&& [ "$ENVIRONMENT" != staging ] \
&& [ "$ENVIRONMENT" != production ]; then
echo "Incorrect value for environment. Please use 'development', 'stagaing', 'testing' or 'production'"
exit 1
fi
echo "Preparing to apply:"
echo "==================="
echo "System: ${SYSTEM}"
echo "Environment: _$ENVIRONMENT"
rm -rf .terraform/terraform.tfstate
mkdir -p .terraform
cp _$ENVIRONMENT/terraform.tfstate ./.terraform/
terraform destroy \
-var "environment=$environment" \
-var-file="../env.$ENVIRONMENT.tfvars" \
-var-file=_$environment/environment.tfvars