-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_create_aws_resources.sh
104 lines (84 loc) · 2.91 KB
/
1_create_aws_resources.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
#!/usr/bin/env bash
cd `dirname $0`
#ls -al
# defines $SUDO and $INSTALLER variables:
source ./detect_installer.sh
# install terraform:
terraform -version || ( echo "terraform not found on the system; installing terraform" && ./install_terraform.sh )
terraform init openshift-terraform-ansible/ec2/
FILES=".aws/credentials terraform.tfvars"
for FILE in $FILES
do
if [ -r "$FILE" ]; then
echo "file $FILE found."
else
if [ -r "${FILE}.example" ]; then
cp ${FILE}.example ${FILE} && echo "file $FILE created from example file." || FAILMSG="could not copy file $FILE created from example file"
if [ "$FAILMSG" != "" ]; then
echo "$FAILMSG" >&2
exit 1
fi
else
echo "Could not create file from example file ${FILE}.example; Not found. Exiting..." >&2
exit 1
fi
fi
while true; do
echo "file `pwd`/$FILE has following content:"
echo "----------------------"
cat $FILE
echo "----------------------"
read -p "Do you wish to change the content? (yes/no) " yn
case "$yn" in
[Yy]* ) vi $FILE;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
done
source ./.aws/credentials
if [ "$AWS_ACCESS_KEY_ID" != "" ]; then
export TF_VAR_aws_access_key=$AWS_ACCESS_KEY_ID
else
echo "AWS Key ID not found in ./.aws/credentials" >&2
exit 1
fi
if [ "$AWS_SECRET_ACCESS_KEY" != "" ]; then
export TF_VAR_aws_secret_key=$AWS_SECRET_ACCESS_KEY
else
echo "AWS Secret Access Key not found in ./.aws/credentials" >&2
exit 1
fi
if [ "$KEY_PATH" != "" ]; then
export TF_VAR_key_path=$KEY_PATH
if [ ! -r "$KEY_PATH" ]; then
echo "Cannot read key file '$KEY_PATH' (as specified in ./.aws/credentials)" >&2
exit 1
fi
else
echo "AWS private key path not found in ./.aws/credentials" >&2
exit 1
fi
echo "--- Retrieving own IP address (this might take a while)"
source ./detect_installer.sh && \
which wget 2>/dev/null 1>/dev/null || \
$SUDO $INSTALL -y wget
export TF_VAR_IP_with_full_access=`wget http://ipinfo.io/ip -qO -`
echo "--- Reviewing Terraform Plan"
DIR=openshift-terraform-ansible/ec2
FILE=$DIR/main.tf
while true; do
# with user input, we need, the following line, which hangs at the end until we send a return:
#tee >(terraform plan -out=terraform.plan $DIR) | tee -a terraform.plan.log
# without user input, this line works better:
terraform plan $@ -out=terraform.plan $DIR | tee -a terraform.plan.log
read -p "Change/Apply plan? Note, that this might induce costs with your IaaS provider (change/apply/quit) " yn
case "$yn" in
[Cc]* ) echo entering variable file; vi terraform.tfvars; echo entering terraform plan file; vi $FILE;;
[Aa]* ) terraform apply terraform.plan; break;;
[Qq]* ) echo "you can edit file $FILE manually and re-run this script at a later time"; break;;
* ) echo "Please answer change, apply or quit.";;
esac
done
# install ansible:
#bash install_ansible.sh