-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.sh
executable file
·68 lines (64 loc) · 1.59 KB
/
app.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
#!/usr/bin/env bash
show_usage()
{
echo "app.sh - bash script to control application status"
echo
echo "Usage:"
echo " ./app.sh <action> <parameters>"
echo
echo "Actions:"
echo " create [env] - create infrastructure using Terraform"
echo " destroy [env] - destroy infrastructure"
echo " provision [env] - provision application on infrastructure"
echo " deploy [env] - deploy configuration for application"
echo
echo "Parameters:"
echo " Environment [env] : dev|prod (required)"
}
ansible_playbook ()
{
# Remove temporary files
rm -rf base/ansible/*.retry
rm -rf base/terraform/.terraform
rm -rf base/terraform/terraform.tf
# Run playbook
cd base/ansible; \
ansible-playbook --vault-id @prompt -i $1 $2 -e env=$3
}
case $1 in
create)
case $2 in
dev|prod)
ansible_playbook ../inventory/localhost ./terraform.yml $2
cd ../terraform && terraform apply
;;
*)
show_usage
;;
esac
;;
destroy)
case $2 in
dev|prod)
ansible_playbook ../inventory/localhost ./terraform.yml $2
cd ../terraform && terraform destroy
;;
*)
show_usage
;;
esac
;;
provision|deploy)
case $2 in
dev|prod)
ansible_playbook ../inventory/ec2.py ./$1.yml $2 $3
;;
*)
show_usage
;;
esac
;;
*)
show_usage
;;
esac