-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsetup.sh
188 lines (172 loc) · 5.21 KB
/
setup.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/sh
printf "\e[1;92m _____ __ __ ______ ____ \e[0m\n"
printf "\e[1;92m |_ _|__ _ __ _ __ __ _ / _| ___ _ __ _ __ ___ \ \ / / _ \ / ___| \e[0m\n"
printf "\e[1;92m | |/ _ \ '__| '__/ _' | |_ / _ \| '__| '_ ' _ \ \ \ / /| |_) | | \e[0m\n"
printf "\e[1;92m | | __/ | | | | (_| | _| (_) | | | | | | | | \ V / | __/| |___ \e[0m\n"
printf "\e[1;92m |_|\___|_| |_| \__,_|_| \___/|_| |_| |_| |_| \_/ |_| \____| \e[0m\n"
printf "\e[1;92m \e[0m\n"
printf "\e[1;92m ____ _ _ \e[0m\n"
printf "\e[1;92m / ___|_ __ ___ __ _| |_(_) ___ _ __ \e[0m\n"
printf "\e[1;92m | | | '__/ _ \/ _' | __| |/ _ \| '_ \ \e[0m\n"
printf "\e[1;92m | |___| | | __/ (_| | |_| | (_) | | | | \e[0m\n"
printf "\e[1;92m \____|_| \___|\__,_|\__|_|\___/|_| |_| \e[0m\n"
printf "\n"
printf "\e[1;77m\e[45m VPC Through Terrafrom Script v1 Author: @ykhsupport (Github) \e[0m\n"
printf "\n"
echo ""
echo "..................Welcome to the Script.................."
echo "Let's start to create a complete VPC through Terraform...."
echo ""
if [[ -d .terraform ]]; then
echo "Provider and variable values are already configured."
echo ""
read -p 'Do you want to reconfigure the variables (Region,VPC_CIDR,ProjectName) file [y/N]: ' con4
case "$con4" in
yes|YES|y|Y)
read -p "Please specify your region: " reconreg
if [ -z $reconreg ]; then
echo ""
echo "No region value entered so it will be take the previous value"
echo ""
else
sed -i '/region/d' ./terraform.tfvars
echo 'region = "-REGION-"' >> ./terraform.tfvars
sed -i "s/-REGION-/"$reconreg"/" ./terraform.tfvars
fi
read -p "Please specify your project name: " reconpname
if [ -z $reconpname ]; then
echo ""
echo "No Project Name entered so it will be take the previous value"
echo ""
else
sed -i '/project/d' ./terraform.tfvars
echo 'project = "-PROJECTNAME-"' >> ./terraform.tfvars
sed -i "s/-PROJECTNAME-/"$reconpname"/" ./terraform.tfvars
fi
read -p "Please specify your vpc_cidr: " reconvcidr
if [ -z $reconvcidr ]; then
echo ""
echo "No VPC CIDR value entered it will be take the previous value"
echo ""
else
sed -i '/vpc_cidr/d' ./terraform.tfvars
echo 'vpc_cidr = "-VPCCIDR-"' >> ./terraform.tfvars
sed -ie "s|-VPCCIDR-|"$reconvcidr"|g" ./terraform.tfvars
fi
;;
esac
else
rm -f ./terraform.tfvars
cat <<EOF >terraform.tfvars
region = "-REGION-"
access_key = "-ACCESSKEY-"
secret_key = "-SECREATKEY-"
project = "-PROJECTNAME-"
vpc_cidr = "-VPCCIDR-"
EOF
read -p "Please specify your region: " reg
if [ -z $reg ]; then
echo "No region value entered"
exit 1
else
sed -i "s/-REGION-/"$reg"/" ./terraform.tfvars
fi
read -p "Please specify your access_key: " akey
if [ -z $akey ]; then
echo "No Access_key entered"
exit 1
else
sed -i "s/-ACCESSKEY-/"$akey"/" ./terraform.tfvars
fi
read -p "Please specify your secret_key: " skey
if [ -z $skey ]; then
echo "No secreat key value entered"
exit 1
else
sed -i "s/-SECREATKEY-/"$skey"/" ./terraform.tfvars
fi
read -p "Please specify your project name: " pname
if [ -z $pname ]; then
echo "No Project Name entered"
exit 1
else
sed -i "s/-PROJECTNAME-/"$pname"/" ./terraform.tfvars
fi
read -p "Please specify your vpc_cidr: " vcidr
if [ -z $vcidr ]; then
echo "No VPC CIDR value entered"
exit 1
else
sed -ie "s|-VPCCIDR-|"$vcidr"|g" ./terraform.tfvars
fi
fi
echo ""
echo "Creating Infrastructure..................."
sleep 1
echo "...................................."
echo "............................."
sleep 1
echo ".................."
echo "......."
sleep 1
echo ""
#Setup Terrafrom under the current working directory
if [[ -d .terraform ]]; then
echo ""
echo "Terrafrom is already installed"
else
read -p 'Do you want to install Terraform on this current directory [y/N]: ' con1
case "$con1" in
yes|YES|y|Y)
echo ""
wget https://releases.hashicorp.com/terraform/0.15.3/terraform_0.15.3_linux_amd64.zip 2>&1
unzip terraform*.zip 2>&1
mv -f terraform /usr/bin/
rm -f terraform*.zip
echo ""
echo "Terraform downloading completed...................."
echo ""
sleep 2
echo "start to connect provider.tf to terraform.........."
echo ""
terraform init
;;
*)
ehco ""
echo "Please re-run the script or install terraform manually"
exit 1
;;
esac
fi
echo ""
read -p 'Do you need to run terraform validate/preview with your mentioned values [y/N]: ' con2
case "$con2" in
yes|YES|y|Y)
terraform validate
echo ""
echo "Validation is successfull."
echo""
sleep 1
echo "Let's run the terraform plan......"
sleep 1
terraform plan
;;
esac
echo ""
read -p 'Do you need to apply the values to your infrastructure [y/N]: ' con3
case "$con3" in
yes|YES|y|Y)
terraform apply -auto-approve
sleep 2
echo ""
echo "Your VPC created successfull......................"
echo ""
echo "................Thank_you................"
echo "..............Yousaf K Hamza................"
echo "[email protected]................"
;;
*)
echo "Please re-run the setup file or manualy handled through terraform"
exit
;;
esac