-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaws_profile_creator.sh
More file actions
94 lines (70 loc) · 2.56 KB
/
aws_profile_creator.sh
File metadata and controls
94 lines (70 loc) · 2.56 KB
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
#!/bin/bash
echo -e "\n>> AWS Profile Creator <<"
echo -e "\nNOTE: awsume to sapphire-payer profile before running script.\n"
AWS_CONF=~/.aws/config
AWS_CONF_CHROME_EXT=~/.aws/config-chrome-ext
echo -e "\nPulling Latest Account List from Prod OU..."
pull_accounts() {
get_accounts=`aws organizations list-accounts-for-parent --parent-id ou-mpfo-uv6625zp --query 'Accounts[*].[JoinedTimestamp,Name,Id]' --output table > ./list-accounts-for-parent.txt`
cat ./list-accounts-for-parent.txt | tr -d "|" | tail -n +4 | sed -e '$d' | sort -f > ./profile_list.txt
rm -rf ./list-accounts-for-parent.txt
}
pull_accounts
scan_accs=`cat ./profile_list.txt | awk '{print$3}'`
for i in $scan_accs; do
while ! [[ `grep -irnw ${AWS_CONF} -e $i` ]]; do
if [ $? -eq 0 ]; then
account=$i
echo -e "\nNew Account Detected :"
fi
break
done
done
if [ -z $account ]; then
echo -e "\nNo New Account Detected. Exiting..."
rm -rf ./profile_list
exit 0
fi
acc_name=`cat ./profile_list.txt | grep $account | awk '{print$2}'`
acc_num=`cat ./profile_list.txt | grep $account | awk '{print$3}'`
echo -e "\n\t\xE2\x9C\x94" $acc_name "|" $acc_num
rm -rf ./profile_list
# echo -e "\n\nEnter Account Name: "
# read acc_name
# get_acc_num() {
# echo -e "\nEnter AWS Account #: "
# read acc_num
# }
# get_acc_num
# while ! [[ "$acc_num" =~ ^[0-9]+$ ]]; do
# echo -e "ERROR: Account number should only be nnumbers."
# get_acc_num
# done
echo -e "\nChoose Region: "
echo -e "\t[1] - eu-west-2 (London)"
echo -e "\t[2] - us-east-2 (Ohio)"
echo -e "\t[*] - Specify region name"
read region
case "$region" in
1) region='eu-west-2';;
2) region='us-east-2';;
*) read region
esac
clear
echo -e "" >> ${AWS_CONF}
echo -e [$acc_name] >> ${AWS_CONF}
echo -e "role_arn = arn:aws:iam::$acc_num:role/OrganizationAccountAccessRole" >> ${AWS_CONF}
echo -e "region = "$region >> ${AWS_CONF}
echo -e "source_profile = sapphire-payer\r" >> ${AWS_CONF}
echo -e "\n\nNew Profile added to ~/.aws/config.\n"
color=`python3 ~/Projects/Sapphire_Systems/generate_color_hex.py`
cat ${AWS_CONF}| tail -n 4
echo -e "" >> ${AWS_CONF_CHROME_EXT}
echo -e [$acc_name] >> ${AWS_CONF_CHROME_EXT}
echo -e "role_arn = arn:aws:iam::$acc_num:role/OrganizationAccountAccessRole" >> ${AWS_CONF_CHROME_EXT}
echo -e "region = "$region >> ${AWS_CONF_CHROME_EXT}
echo -e "color = "$color"\r" >> ${AWS_CONF_CHROME_EXT}
echo -e "\n\nNew Profile added to ~/.aws/config-chrome-ext.\n"
cat ${AWS_CONF_CHROME_EXT} | tail -n 4
cat ${AWS_CONF_CHROME_EXT} | tail -n 4 | pbcopy
echo -e "\n\nPaste clipboard to AWS Extend Switch Roles Chrome Extension..."