-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
71 lines (59 loc) · 1.52 KB
/
init.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
65
66
67
68
69
70
71
if [[ -e "this.init.lock" ]]; then
echo
echo "[!][ERROR]: Lock exists"
echo
echo "Terraform workspace available:"
terraform workspace list
echo
exit 1
fi
## install terraform and packer
dpkg-query -l terraform packer >/dev/null || {
apt-get update && apt-get install -y gnupg software-properties-common curl;
curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add -;
apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main";
apt-get update && apt-get install terraform packer;
}
## set access token
if [ -z "${DIGITALOCEAN_ACCESS_TOKEN}" ]; then
echo
echo "[!][ERROR]: No DIGITALOCEAN_ACCESS_TOKEN token available"
echo
exit 1
fi
## start with development workspace
workspace=development
echo
## init packer plugin
/usr/bin/packer init modules/frontend/packer/packer.pkr.hcl
echo
## init terraform
terraform fmt
terraform init
if [ $? -ne 0 ]; then
echo
echo "[!][ERROR]: Terraform init"
echo
exit 1
fi
echo
# create terraform workspace
if [ "$(terraform workspace list | grep ${workspace})" == "" ]; then
terraform workspace new ${workspace}
fi
if [ $? -ne 0 ]; then
echo
echo "[!][ERROR]: Terraform workspace ${workspace} not available"
echo
exit 1
fi
echo
echo "[!][INFO]: Running terraform plan to ${workspace}.plan.out.txt"
terraform plan -out ${workspace}.plan.out -no-color 2>&1 > ${workspace}.plan.out.txt
echo
if [ $? -eq 0 ]; then
echo
echo "[X][LOCKED]: Init lock enabled"
echo
touch this.init.lock
fi