-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_run_terraform
executable file
·79 lines (60 loc) · 1.62 KB
/
_run_terraform
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
72
73
74
75
76
77
78
79
#! /bin/bash
clear
option=$1
if [[ -z $option ]]; then
echo """
======================================================================
Choose a number for what you want to provision via terraform:
1. Static Site (S3+Cloudfront)
2. Lambda Emailer
(Note: you can pass a number straight through as script argument)
======================================================================
"""
read option
fi
# Validate option
if [[ $option =~ ^[0-9]+$ && $option -ge 1 && $option -le 2 ]]; then
# Set params based on selected option
if [[ $option = 1 ]]; then
script_path=terraform/static_site
entity="Static Site"
fi
if [[ $option = 2 ]]; then
script_path=terraform/lambda_emailer
entity="Lambda Emailer"
fi
else
echo "You needed a number between 1-2"
exit
fi
# Ensure the terraform dirs have been initialized
if [[ ! -d $script_path/.terraform ]]; then
echo $script_path
terraform init $script_path/
fi
# Define pause-messaging function
function pause_before_next_stage() {
echo -e """
=======================================
PROVISIONING FOR: ${1}
READY FOR NEXT STAGE: ${2}
\033[32mNow is a safe time to quit.\033[0m
\033[31mDo NOT quit while terraform is running!\033[0m
Press Enter to Continue
Press ctrl+c to Quit
=======================================
"""
read
clear
}
###########################
# Terraform mini-pipeline #
###########################
# Make env vars available to
source .env
# Plan
pause_before_next_stage $entity "terraform plan"
terraform plan $script_path
# Apply
pause_before_next_stage $entity "terraform apply"
terraform apply $script_path