forked from DuckbillGroup/onboarding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-resources.sh
executable file
·84 lines (58 loc) · 2.65 KB
/
create-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
#!/usr/bin/env bash
# Creates all AWS IAM resources required for Duckbill Group remote access.
set -euo pipefail
this_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
user_arn=$(aws sts get-caller-identity --output text --query 'Arn' | tr -d '\r')
account_number=$(aws sts get-caller-identity --output text --query 'Account' | tr -d '\r')
cat <<EOM
Please enter your customer name slug. This is a short, lower-case slug
that identifies your company, e.g. 'acme-corp'
Duckbill Group will need to know this value, so that we can set up our own
infrastructure for you.
EOM
read -rp 'Customer name slug: ' customer_name_slug
cat <<EOM
Please enter the name of the S3 bucket in which you are storing Cost and Usage Reports.
EOM
read -rp 'CUR S3 Bucket Name: ' cur_bucket_name
cat <<EOM
Please enter the External ID provided to you by Duckbill Cloud Economists
EOM
read -rp 'External ID: ' external_id
sed "s/CUSTOMER_NAME_SLUG/${customer_name_slug}/g;s/CUR_BUCKET_NAME/${cur_bucket_name}/g" \
"${this_dir}/cur-ingest-pipeline-policy.json.template" > "${this_dir}/cur-ingest-pipeline-policy.json"
sed "s/EXTERNAL_ID/${external_id}/g" \
"${this_dir}/assume-role-trust-policy.json.template" > "${this_dir}/assume-role-trust-policy.json"
echo "Logged into AWS as ${user_arn}"
echo "Adding Duckbill Group role and policies..."
aws iam create-role \
--role-name DuckbillGroupRole \
--assume-role-policy-document "file://${this_dir}/assume-role-trust-policy.json"
aws iam create-policy \
--policy-name DuckbillGroupBilling \
--policy-document "file://${this_dir}/billing-policy.json"
aws iam create-policy \
--policy-name DuckbillGroupResourceDiscovery \
--policy-document "file://${this_dir}/resource-discovery-policy.json"
aws iam create-policy \
--policy-name DuckbillGroupCURIngestPipeline \
--policy-document "file://${this_dir}/cur-ingest-pipeline-policy.json"
aws iam attach-role-policy \
--role-name DuckbillGroupRole \
--policy-arn arn:aws:iam::aws:policy/job-function/ViewOnlyAccess
aws iam attach-role-policy \
--role-name DuckbillGroupRole \
--policy-arn arn:aws:iam::aws:policy/job-function/Billing
aws iam attach-role-policy \
--role-name DuckbillGroupRole \
--policy-arn arn:aws:iam::aws:policy/AWSSavingsPlansReadOnlyAccess
aws iam attach-role-policy \
--role-name DuckbillGroupRole \
--policy-arn "arn:aws:iam::${account_number}:policy/DuckbillGroupBilling"
aws iam attach-role-policy \
--role-name DuckbillGroupRole \
--policy-arn "arn:aws:iam::${account_number}:policy/DuckbillGroupResourceDiscovery"
aws iam attach-role-policy \
--role-name DuckbillGroupRole \
--policy-arn "arn:aws:iam::${account_number}:policy/DuckbillGroupCURIngestPipeline"
echo "Done!"