forked from domain-protect/domain-protect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
414 lines (386 loc) · 17.3 KB
/
main.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
module "kms" {
source = "./terraform-modules/kms"
project = var.project
region = var.region
environment = local.env
}
module "lambda-role" {
source = "./terraform-modules/iam"
project = var.project
region = var.region
security_audit_role_name = var.security_audit_role_name
kms_arn = module.kms.kms_arn
permissions_boundary_arn = var.permissions_boundary_arn
environment = local.env
}
module "lambda-slack" {
source = "./terraform-modules/lambda-slack"
runtime = var.runtime
platform = var.platform
memory_size = var.memory_size_slack
project = var.project
lambda_role_arn = module.lambda-role.lambda_role_arn
kms_arn = module.kms.kms_arn
sns_topic_arn = module.sns.sns_topic_arn
dlq_sns_topic_arn = module.sns-dead-letter-queue.sns_topic_arn
slack_channels = local.env == "dev" ? var.slack_channels_dev : var.slack_channels
slack_webhook_urls = local.env == "dev" && length(var.slack_webhook_urls_dev) > 0 ? var.slack_webhook_urls_dev : var.slack_webhook_urls
slack_webhook_type = var.slack_webhook_type
slack_emoji = var.slack_emoji
slack_fix_emoji = var.slack_fix_emoji
slack_new_emoji = var.slack_new_emoji
slack_username = var.slack_username
environment = local.env
}
module "lambda" {
source = "./terraform-modules/lambda"
lambdas = var.lambdas
runtime = var.runtime
platform = var.platform
memory_size = var.memory_size
project = var.project
security_audit_role_name = var.security_audit_role_name
external_id = var.external_id
org_primary_account = var.org_primary_account
lambda_role_arn = module.lambda-role.lambda_role_arn
kms_arn = module.kms.kms_arn
sns_topic_arn = module.sns.sns_topic_arn
dlq_sns_topic_arn = module.sns-dead-letter-queue.sns_topic_arn
state_machine_arn = module.step-function.state_machine_arn
allowed_regions = var.allowed_regions
ip_time_limit = var.ip_time_limit
environment = local.env
}
module "lambda-accounts" {
source = "./terraform-modules/lambda-accounts"
lambdas = ["accounts"]
runtime = var.runtime
platform = var.platform
memory_size = var.memory_size
project = var.project
security_audit_role_name = var.security_audit_role_name
external_id = var.external_id
org_primary_account = var.org_primary_account
lambda_role_arn = module.accounts-role.lambda_role_arn
kms_arn = module.kms.kms_arn
sns_topic_arn = module.sns.sns_topic_arn
dlq_sns_topic_arn = module.sns-dead-letter-queue.sns_topic_arn
state_machine_arn = module.step-function.state_machine_arn
environment = local.env
}
module "accounts-role" {
source = "./terraform-modules/iam"
project = var.project
region = var.region
security_audit_role_name = var.security_audit_role_name
kms_arn = module.kms.kms_arn
state_machine_arn = module.step-function.state_machine_arn
policy = "accounts"
permissions_boundary_arn = var.permissions_boundary_arn
environment = local.env
}
module "lambda-scan" {
source = "./terraform-modules/lambda-scan"
lambdas = ["scan"]
runtime = var.runtime
platform = var.platform
memory_size = var.memory_size
project = var.project
security_audit_role_name = var.security_audit_role_name
external_id = var.external_id
org_primary_account = var.org_primary_account
lambda_role_arn = module.lambda-role.lambda_role_arn
kms_arn = module.kms.kms_arn
sns_topic_arn = module.sns.sns_topic_arn
dlq_sns_topic_arn = module.sns-dead-letter-queue.sns_topic_arn
bugcrowd = var.bugcrowd
bugcrowd_api_key = var.bugcrowd_api_key
bugcrowd_email = var.bugcrowd_email
bugcrowd_state = var.bugcrowd_state
hackerone = var.hackerone
hackerone_api_token = var.hackerone_api_token
environment = local.env
production_environment = local.production_environment
}
module "lambda-takeover" {
#checkov:skip=CKV_AWS_274:role is ElasticBeanstalk admin, not full Administrator Access
count = local.takeover ? 1 : 0
source = "./terraform-modules/lambda-takeover"
runtime = var.runtime
platform = var.platform
memory_size = var.memory_size_slack
project = var.project
lambda_role_arn = module.takeover-role.*.lambda_role_arn[0]
kms_arn = module.kms.kms_arn
sns_topic_arn = module.sns.sns_topic_arn
dlq_sns_topic_arn = module.sns-dead-letter-queue.sns_topic_arn
environment = local.env
}
module "takeover-role" {
count = local.takeover ? 1 : 0
source = "./terraform-modules/iam"
project = var.project
region = var.region
security_audit_role_name = var.security_audit_role_name
kms_arn = module.kms.kms_arn
takeover = local.takeover
policy = "takeover"
permissions_boundary_arn = var.permissions_boundary_arn
environment = local.env
}
module "lambda-resources" {
count = local.takeover ? 1 : 0
source = "./terraform-modules/lambda-resources"
lambdas = ["resources"]
runtime = var.runtime
memory_size = var.memory_size_slack
project = var.project
lambda_role_arn = module.resources-role.*.lambda_role_arn[0]
kms_arn = module.kms.kms_arn
sns_topic_arn = module.sns.sns_topic_arn
dlq_sns_topic_arn = module.sns-dead-letter-queue.sns_topic_arn
environment = local.env
}
module "resources-role" {
count = local.takeover ? 1 : 0
source = "./terraform-modules/iam"
project = var.project
region = var.region
security_audit_role_name = var.security_audit_role_name
kms_arn = module.kms.kms_arn
policy = "resources"
permissions_boundary_arn = var.permissions_boundary_arn
environment = local.env
}
module "cloudwatch-event" {
source = "./terraform-modules/cloudwatch"
project = var.project
lambda_function_arns = module.lambda.lambda_function_arns
lambda_function_names = module.lambda.lambda_function_names
lambda_function_alias_names = module.lambda.lambda_function_alias_names
schedule = var.reports_schedule
takeover = local.takeover
update_schedule = local.env == local.production_environment ? var.update_schedule : var.update_schedule_nonprod
update_lambdas = var.update_lambdas
environment = local.env
}
module "resources-event" {
count = local.takeover ? 1 : 0
source = "./terraform-modules/cloudwatch"
project = var.project
lambda_function_arns = module.lambda-resources[0].lambda_function_arns
lambda_function_names = module.lambda-resources[0].lambda_function_names
lambda_function_alias_names = module.lambda-resources[0].lambda_function_alias_names
schedule = var.reports_schedule
takeover = local.takeover
update_schedule = local.env == local.production_environment ? var.scan_schedule : var.scan_schedule_nonprod
update_lambdas = var.update_lambdas
environment = local.env
}
module "accounts-event" {
source = "./terraform-modules/cloudwatch"
project = var.project
lambda_function_arns = module.lambda-accounts.lambda_function_arns
lambda_function_names = module.lambda-accounts.lambda_function_names
lambda_function_alias_names = module.lambda-accounts.lambda_function_alias_names
schedule = local.env == local.production_environment ? var.scan_schedule : var.scan_schedule_nonprod
takeover = local.takeover
update_schedule = local.env == local.production_environment ? var.scan_schedule : var.scan_schedule_nonprod
update_lambdas = var.update_lambdas
environment = local.env
}
module "sns" {
source = "./terraform-modules/sns"
project = var.project
region = var.region
kms_arn = module.kms.kms_arn
environment = local.env
}
module "sns-dead-letter-queue" {
source = "./terraform-modules/sns"
project = var.project
region = var.region
dead_letter_queue = true
kms_arn = module.kms.kms_arn
environment = local.env
}
module "lambda-cloudflare" {
count = var.cloudflare ? 1 : 0
source = "./terraform-modules/lambda-cloudflare"
lambdas = var.cloudflare_lambdas
runtime = var.runtime
platform = var.platform
memory_size = var.memory_size
project = var.project
cf_api_key = var.cf_api_key
lambda_role_arn = module.lambda-role.lambda_role_arn
kms_arn = module.kms.kms_arn
security_audit_role_name = var.security_audit_role_name
external_id = var.external_id
org_primary_account = var.org_primary_account
sns_topic_arn = module.sns.sns_topic_arn
dlq_sns_topic_arn = module.sns-dead-letter-queue.sns_topic_arn
production_environment = local.production_environment
bugcrowd = var.bugcrowd
bugcrowd_api_key = var.bugcrowd_api_key
bugcrowd_email = var.bugcrowd_email
bugcrowd_state = var.bugcrowd_state
hackerone = var.hackerone
hackerone_api_token = var.hackerone_api_token
environment = local.env
}
module "cloudflare-event" {
count = var.cloudflare ? 1 : 0
source = "./terraform-modules/cloudwatch"
project = var.project
lambda_function_arns = module.lambda-cloudflare[0].lambda_function_arns
lambda_function_names = module.lambda-cloudflare[0].lambda_function_names
lambda_function_alias_names = module.lambda-cloudflare[0].lambda_function_alias_names
schedule = local.env == local.production_environment ? var.scan_schedule : var.scan_schedule_nonprod
takeover = local.takeover
update_schedule = local.env == local.production_environment ? var.scan_schedule : var.scan_schedule_nonprod
update_lambdas = var.update_lambdas
environment = local.env
}
module "dynamodb" {
source = "./terraform-modules/dynamodb"
project = var.project
kms_arn = module.kms.kms_arn
rcu = var.rcu
wcu = var.wcu
environment = local.env
}
module "step-function-role" {
source = "./terraform-modules/iam"
project = var.project
region = var.region
security_audit_role_name = var.security_audit_role_name
kms_arn = module.kms.kms_arn
policy = "state"
assume_role_policy = "state"
permissions_boundary_arn = var.permissions_boundary_arn
environment = local.env
}
module "step-function" {
source = "./terraform-modules/step-function"
project = var.project
lambda_arn = module.lambda-scan.lambda_function_arns["scan"]
role_arn = module.step-function-role.lambda_role_arn
kms_arn = module.kms.kms_arn
environment = local.env
}
module "dynamodb-ips" {
count = var.ip_address ? 1 : 0
source = "./terraform-modules/dynamodb-ips"
project = var.project
kms_arn = module.kms.kms_arn
environment = local.env
}
module "step-function-ips" {
count = var.ip_address ? 1 : 0
source = "./terraform-modules/step-function"
project = var.project
purpose = "ips"
lambda_arn = module.lambda-scan-ips[0].lambda_function_arns["scan-ips"]
role_arn = module.step-function-role.lambda_role_arn
kms_arn = module.kms.kms_arn
environment = local.env
}
module "lambda-role-ips" {
count = var.ip_address ? 1 : 0
source = "./terraform-modules/iam"
project = var.project
region = var.region
security_audit_role_name = var.security_audit_role_name
kms_arn = module.kms.kms_arn
policy = "lambda"
role_name = "lambda-ips"
permissions_boundary_arn = var.permissions_boundary_arn
environment = local.env
}
module "lambda-scan-ips" {
count = var.ip_address ? 1 : 0
source = "./terraform-modules/lambda-scan-ips"
lambdas = ["scan-ips"]
runtime = var.runtime
platform = var.platform
memory_size = var.memory_size
project = var.project
security_audit_role_name = var.security_audit_role_name
external_id = var.external_id
org_primary_account = var.org_primary_account
lambda_role_arn = module.lambda-role-ips[0].lambda_role_arn
kms_arn = module.kms.kms_arn
sns_topic_arn = module.sns.sns_topic_arn
dlq_sns_topic_arn = module.sns-dead-letter-queue.sns_topic_arn
production_environment = local.production_environment
allowed_regions = var.allowed_regions
ip_time_limit = var.ip_time_limit
bugcrowd = var.bugcrowd
bugcrowd_api_key = var.bugcrowd_api_key
bugcrowd_email = var.bugcrowd_email
bugcrowd_state = var.bugcrowd_state
hackerone = var.hackerone
hackerone_api_token = var.hackerone_api_token
environment = local.env
}
module "accounts-role-ips" {
count = var.ip_address ? 1 : 0
source = "./terraform-modules/iam"
project = var.project
region = var.region
security_audit_role_name = var.security_audit_role_name
kms_arn = module.kms.kms_arn
state_machine_arn = module.step-function-ips[0].state_machine_arn
policy = "accounts"
role_name = "accounts-ips"
permissions_boundary_arn = var.permissions_boundary_arn
environment = local.env
}
module "lambda-accounts-ips" {
count = var.ip_address ? 1 : 0
source = "./terraform-modules/lambda-accounts"
lambdas = ["accounts-ips"]
runtime = var.runtime
platform = var.platform
memory_size = var.memory_size
project = var.project
security_audit_role_name = var.security_audit_role_name
external_id = var.external_id
org_primary_account = var.org_primary_account
lambda_role_arn = module.accounts-role-ips[0].lambda_role_arn
kms_arn = module.kms.kms_arn
sns_topic_arn = module.sns.sns_topic_arn
dlq_sns_topic_arn = module.sns-dead-letter-queue.sns_topic_arn
state_machine_arn = module.step-function-ips[0].state_machine_arn
environment = local.env
}
module "accounts-event-ips" {
count = var.ip_address ? 1 : 0
source = "./terraform-modules/cloudwatch"
project = var.project
lambda_function_arns = module.lambda-accounts-ips[0].lambda_function_arns
lambda_function_names = module.lambda-accounts-ips[0].lambda_function_names
lambda_function_alias_names = module.lambda-accounts-ips[0].lambda_function_alias_names
schedule = local.env == local.production_environment ? var.ip_scan_schedule : var.ip_scan_schedule_nonprod
takeover = local.takeover
update_schedule = local.env == local.production_environment ? var.ip_scan_schedule : var.ip_scan_schedule_nonprod
update_lambdas = var.update_lambdas
environment = local.env
}
module "lamdba-stats" {
source = "./terraform-modules/lambda-stats"
runtime = var.runtime
platform = var.platform
memory_size = var.memory_size
project = var.project
kms_arn = module.kms.kms_arn
lambda_role_arn = module.lambda-role.lambda_role_arn
sns_topic_arn = module.sns.sns_topic_arn
dlq_sns_topic_arn = module.sns-dead-letter-queue.sns_topic_arn
schedule_expression = var.stats_schedule
org_primary_account = var.org_primary_account
security_audit_role_name = var.security_audit_role_name
external_id = var.external_id
environment = local.env
}