-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcreate_users_and_accesskey_template.sh
executable file
·62 lines (49 loc) · 1.31 KB
/
create_users_and_accesskey_template.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
#!/bin/bash
# Simple script just to generate the initial template, which
# 1. creates IAM Users
# 2. assigns IAM User to the same existing IAM Group(s)
# 3. creates IAM Access Key and Secret for each IAM User
OUTPUT_FILE=tmp_users.template
declare -a USERS=(
"Firstname Lastname"
)
# Add Header
cat > ${OUTPUT_FILE} << EOF
AWSTemplateFormatVersion: '2010-09-09'
Description: >-
Create IAM Users and assign users to the corresponding IAM Groups.
Resources:
EOF
# Add Resources
for user in "${USERS[@]}"
do
echo "Adding $user"
name_no_space=${user//[ ]/}
user_name=$(echo "print('${user//[ ]/.}'.lower())" | python)
cat >> ${OUTPUT_FILE} << EOF
${name_no_space}IamUser:
Type: AWS::IAM::User
Properties:
UserName: ${user_name}
Groups:
- Developers
${name_no_space}IamAccessKey:
DependsOn: ${name_no_space}IamUser
Type: AWS::IAM::AccessKey
Properties:
UserName: ${user_name}
EOF
done
# Add Outputs
echo "Outputs:" >> ${OUTPUT_FILE}
for user in "${USERS[@]}"
do
name_no_space=${user//[ ]/}
user_name=$(echo "print('${user//[ ]/.}'.lower())" | python)
cat >> ${OUTPUT_FILE} << EOF
${name_no_space}IamAccessKeyId:
Value: !Ref ${name_no_space}IamAccessKey
${name_no_space}IamSecretAccessKey:
Value: !GetAtt ${name_no_space}IamAccessKey.SecretAccessKey
EOF
done