generated from rhythmictech/terraform-terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurityhub.tf
42 lines (35 loc) · 1.31 KB
/
securityhub.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
resource "aws_cloudwatch_event_rule" "securityhub_to_datadog" {
count = var.enable_securityhub_notifications ? 1 : 0
name_prefix = substr("securityhub-finding-${var.name}", 0, 35)
description = "Match on SecurityHub findings (Datadog)"
event_pattern = jsonencode({
source = ["aws.securityhub"]
detail-type = ["Security Hub Findings - Imported"]
})
}
resource "aws_cloudwatch_event_target" "securityhub_to_datadog" {
count = var.enable_securityhub_notifications ? 1 : 0
rule = aws_cloudwatch_event_rule.securityhub_to_datadog[0].name
target_id = "SendToDatadogLogForwarder"
arn = try(aws_cloudformation_stack.datadog_forwarder[0].outputs.DatadogForwarderArn, "")
input_transformer {
input_paths = {
detail = "$.detail"
}
input_template = <<EOF
{
"detail-type": "Security Hub Findings - Imported",
"source": "aws.securityhub",
"detail": <detail>
}
EOF
}
}
resource "aws_lambda_permission" "securityhub_trigger" {
count = var.enable_securityhub_notifications ? 1 : 0
action = "lambda:InvokeFunction"
function_name = try(aws_cloudformation_stack.datadog_forwarder[0].outputs.DatadogForwarderArn, "")
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.securityhub_to_datadog[0].arn
statement_id = "SecurityHubTrigger"
}