forked from DuckbillGroup/onboarding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
duckbill-iam-role.tf
243 lines (200 loc) · 6.32 KB
/
duckbill-iam-role.tf
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# These Terraform resources create a remote access role for Duckbill Group.
# Variables
variable "customer_name_slug" {
type = string
description = "A short, lower-case slug that identifies your company, e.g. 'acme-corp'. Duckbill Group provided this to you in the Client Onboarding Guide."
}
variable "cur_bucket_name" {
type = string
description = "Name of the S3 bucket in which you are storing Cost and Usage Reports."
}
variable "external_id" {
type = string
description = "The External ID used when Duckbill assumes the role. Duckbill Group provided this to you in the Client Onboarding Guide."
}
locals {
internal_customer_id = split("-", var.external_id)[0]
}
# Terraform configuration
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
required_version = ">= 0.13"
}
provider "aws" {
region = "us-east-1"
}
# DuckbillGroup IAM Role
data "aws_iam_policy_document" "DuckbillGroup_AssumeRole_policy_document" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "AWS"
identifiers = ["753095100886"]
}
condition {
test = "StringEquals"
variable = "sts:ExternalId"
values = [var.external_id]
}
}
}
resource "aws_iam_role" "DuckbillGroupRole" {
name = "DuckbillGroupRole"
assume_role_policy = data.aws_iam_policy_document.DuckbillGroup_AssumeRole_policy_document.json
}
# DuckbillGroupBilling IAM Policy
data "aws_iam_policy_document" "DuckbillGroupBilling_policy_document" {
statement {
effect = "Allow"
actions = [
"ce:*",
"cur:DescribeReportDefinitions",
"aws-portal:ViewBilling",
"aws-portal:ViewUsage",
"budgets:ViewBudget",
"compute-optimizer:Get*",
"glue:BatchGetJobs",
"glue:ListJobs",
"pricing:GetProducts"
]
resources = ["*"]
}
}
resource "aws_iam_policy" "DuckbillGroupBilling_policy" {
name = "DuckbillGroupBilling"
policy = data.aws_iam_policy_document.DuckbillGroupBilling_policy_document.json
}
# DuckbillGroupResourceDiscovery IAM Policy
data "aws_iam_policy_document" "DuckbillGroupResourceDiscovery_policy_document" {
statement {
effect = "Allow"
actions = [
"acm:Describe*",
"apigateway:GET",
"batch:Describe*",
"cloudhsm:Describe*",
"cloudhsm:List*",
"cloudwatch:Describe*",
"codebuild:BatchGetProjects",
"codecommit:BatchGetRepositories",
"cognito-identity:Describe*",
"cognito-idp:Describe*",
"dax:Describe*",
"dlm:Get*",
"dms:Describe*",
"ec2:Describe*",
"eks:Describe*",
"eks:List*",
"elasticbeanstalk:ListTagsForResource",
"elasticfilesystem:Describe*",
"elasticmapreduce:Describe*",
"es:ListTags",
"es:DescribeReservedElasticsearchInstances",
"fsx:Describe*",
"glue:Get*",
"glue:List*",
"health:Describe*",
"iam:GetPolicyVersion",
"iam:GetRole",
"iam:GetUser",
"kafka:List*",
"kinesis:Describe*",
"kinesis:List*",
"kms:Describe*",
"kms:List*",
"lambda:Get*",
"lambda:List*",
"lightsail:GetInstances",
"lightsail:GetLoadBalancers",
"lightsail:GetRelationalDatabases",
"macie2:Describe*",
"macie2:ListTagsForResources",
"macie2:GetBucketStatistics",
"macie2:GetMacieSession",
"macie2:GetUsageStatistics",
"macie2:GetUsageTotals",
"medialive:Describe*",
"medialive:List*",
"mq:List*",
"redshift:Describe*",
"s3:GetAnalyticsConfiguration",
"s3:GetBucket*",
"s3:GetReplication*",
"s3:GetStorageLensDashboard",
"s3:GetStorageLensConfiguration",
"s3:ListStorageLensConfigurations",
"secretsmanager:ListSecrets",
"shield:List*",
"snowball:List*",
"sns:GetTopicAttributes",
"ssm:Describe*",
"tag:Get*"
]
resources = ["*"]
}
}
resource "aws_iam_policy" "DuckbillGroupResourceDiscovery_policy" {
name = "DuckbillGroupResourceDiscovery"
policy = data.aws_iam_policy_document.DuckbillGroupResourceDiscovery_policy_document.json
}
# DuckbillGroupCURIngestPipeline IAM Policy
data "aws_iam_policy_document" "DuckbillGroupCURIngestPipeline_policy_document" {
statement {
effect = "Allow"
actions = [
"s3:ListBucket",
"s3:GetObject"
]
resources = [
"arn:aws:s3:::${var.cur_bucket_name}",
"arn:aws:s3:::${var.cur_bucket_name}/*"
]
}
statement {
effect = "Allow"
actions = [
"s3:ListBucket",
"s3:PutObject",
"s3:PutObjectAcl"
]
resources = [
"arn:aws:s3:::dbg-cur-ingest-${var.customer_name_slug}",
"arn:aws:s3:::dbg-cur-ingest-${var.customer_name_slug}/*",
"arn:aws:s3:::dbg-cur-ingest-${local.internal_customer_id}",
"arn:aws:s3:::dbg-cur-ingest-${local.internal_customer_id}/*"
]
}
}
resource "aws_iam_policy" "DuckbillGroupCURIngestPipeline_policy" {
name = "DuckbillGroupCURIngestPipeline"
policy = data.aws_iam_policy_document.DuckbillGroupCURIngestPipeline_policy_document.json
}
# Attach IAM Policies to DuckbillGroup Role
resource "aws_iam_role_policy_attachment" "duckbill-attach-ViewOnlyAccess" {
role = aws_iam_role.DuckbillGroupRole.name
policy_arn = "arn:aws:iam::aws:policy/job-function/ViewOnlyAccess"
}
resource "aws_iam_role_policy_attachment" "duckbill-attach-Billing" {
role = aws_iam_role.DuckbillGroupRole.name
policy_arn = "arn:aws:iam::aws:policy/job-function/Billing"
}
resource "aws_iam_role_policy_attachment" "duckbill-attach-SavingsPlans" {
role = aws_iam_role.DuckbillGroupRole.name
policy_arn = "arn:aws:iam::aws:policy/AWSSavingsPlansReadOnlyAccess"
}
resource "aws_iam_role_policy_attachment" "duckbill-attach-DuckbillGroupBilling" {
role = aws_iam_role.DuckbillGroupRole.name
policy_arn = aws_iam_policy.DuckbillGroupBilling_policy.arn
}
resource "aws_iam_role_policy_attachment" "duckbill-attach-DuckbillGroupResourceDiscovery_policy" {
role = aws_iam_role.DuckbillGroupRole.name
policy_arn = aws_iam_policy.DuckbillGroupResourceDiscovery_policy.arn
}
resource "aws_iam_role_policy_attachment" "duckbill-attach-DuckbillGroupCURIngestPipeline_policy" {
role = aws_iam_role.DuckbillGroupRole.name
policy_arn = aws_iam_policy.DuckbillGroupCURIngestPipeline_policy.arn
}