-
Notifications
You must be signed in to change notification settings - Fork 0
/
thafform
executable file
·49 lines (43 loc) · 1.17 KB
/
thafform
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
#!/bin/sh
if [ -f .env ]; then
source .env
else
echo "ensure .env exists"
exit 0
fi
if [[ ! `which terraform` ]]; then
echo "install terraform.io"
exit 0
fi
WORKSPACE=$(terraform workspace show)
# edit:
# * $0 workspace list
# * $0 workspace select WORKSPACE_NAME
# * cat <<< $(jq 'MATCH_SYNTAX = EDITED_JSON' terraform.tfvars.json) > terraform.tfvars.json
case $1 in
"workspace")
case $2 in
"select"|"new")
if test -f terraform.tfvars.json; then
aws s3 cp --quiet terraform.tfvars.json "$DST_PATH/$WORKSPACE.json"
fi
terraform $@
aws s3 cp --quiet "$DST_PATH/`terraform workspace show`.json" terraform.tfvars.json || cp terraform.tfvars.template.json terraform.tfvars.json
exit 0
;;
esac
;;
"download")
if [ -z "$3" ]; then
aws s3 cp --quiet "$DST_PATH/$3" "terraform.$3.tfvars.json" || echo "chosen workspace doesn't exist remotely"
else
echo "usage: $0 $1 WORKSPACE_NAME"
fi
exit 0
;;
"save")
aws s3 cp --quiet terraform.tfvars.json "$DST_PATH/$WORKSPACE.json"
exit 0
;;
esac
terraform $@