-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam-update
executable file
·38 lines (27 loc) · 1.08 KB
/
iam-update
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
#!/usr/bin/env bash
path="$HOME/Projects/occs/git-repos/aws/IAM"
env=$(aws iam list-account-aliases --output text | awk '{print $2}')
ENV=$(echo "${env}" | tr '[:lower:]' '[:upper:]')
echo "You are logged into $ENV environment"
yaml_path="${env}"
json_path=$(echo "${env}" | cut -c 5-)
if [[ ! "${env}" =~ 'INT' && ! "${env}" =~ 'SBOX' ]]
then
yaml_path='QA-PROD'
fi
if [[ "${env}" =~ 'SBOX' ]]
then
yaml_path='SBOX'
fi
if [[ "${env}" =~ 'INT' ]]; then
yaml_path='INT'
fi
echo ${yaml_path}
echo "Updating $ENV IAM..."
echo "Uploading IAM policy file to S3..."
sleep 2
cd "${path}" || exit
aws s3 cp iam-policies-and-roles-${yaml_path}.yaml s3://"${env}"-cloudformation-templates-us-east-1/iam/iam-policies-and-roles-${yaml_path}.yaml --sse
echo "Creating CFN stack now..."
aws cloudformation update-stack --cli-input-json file://param-files/create-stack-"${json_path}"-iam-policies-and-roles.json --template-url https://s3.amazonaws.com/"${env}"-cloudformation-templates-us-east-1/iam/iam-policies-and-roles-${yaml_path}.yaml --capabilities CAPABILITY_NAMED_IAM
echo "Done..."