forked from DNXLabs/terraform-aws-securityhub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent-to-email.tf
47 lines (43 loc) · 1.49 KB
/
event-to-email.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
resource "aws_cloudwatch_event_target" "sns" {
count = var.alarm_email != "" ? 1 : 0
rule = aws_cloudwatch_event_rule.securityhub[0].name
target_id = "securityhub-to-sns"
arn = aws_sns_topic.securityhub[0].arn
input_transformer {
input_template = "\"SecurityHub <aws_account_id>/<aws_region> <severity> <title> <remediation_url>\""
input_paths = {
"aws_account_id" = "$.detail.findings[0].AwsAccountId"
"aws_region" = "$.region"
"remediation_url" = "$.detail.findings[0].ProductFields.RecommendationUrl"
"severity" = "$.detail.findings[0].Severity.Label"
"title" = "$.detail.findings[0].Title"
}
}
}
resource "aws_sns_topic" "securityhub" {
count = var.alarm_email != "" ? 1 : 0
name_prefix = "securityhub-"
}
resource "aws_sns_topic_policy" "default" {
count = var.alarm_email != "" ? 1 : 0
arn = aws_sns_topic.securityhub[0].arn
policy = data.aws_iam_policy_document.sns_topic_policy[0].json
}
data "aws_iam_policy_document" "sns_topic_policy" {
count = var.alarm_email != "" ? 1 : 0
statement {
effect = "Allow"
actions = ["SNS:Publish"]
principals {
type = "Service"
identifiers = ["events.amazonaws.com"]
}
resources = [aws_sns_topic.securityhub[0].arn]
}
}
resource "aws_sns_topic_subscription" "email" {
count = var.alarm_email != "" ? 1 : 0
topic_arn = aws_sns_topic.securityhub[0].arn
protocol = "email"
endpoint = try(var.alarm_email, "")
}