generated from cloudposse/terraform-example-module
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy patheventbridge.tf
109 lines (89 loc) · 3.18 KB
/
eventbridge.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
#-----------------------------------------------------------------------------------------------------------------------
# Optionally configure Event Bridge (formerly CloudWatchEvents) Rules and SNS subscriptions
# We would like the SNS Topic to be encrypted, and EventBridge requires sufficient permissions for the KMS key
# https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-cwe-integration-types.html
# https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-use-resource-based.html
#-----------------------------------------------------------------------------------------------------------------------
module "sns_kms_key_label" {
source = "cloudposse/label/null"
version = "0.25.0"
count = local.create_sns_topic ? 1 : 0
attributes = ["securityhub"]
context = module.this.context
}
module "sns_kms_key" {
source = "cloudposse/kms-key/aws"
version = "0.12.2"
count = local.create_sns_topic ? 1 : 0
name = local.create_sns_topic ? module.sns_kms_key_label[0].id : ""
description = "KMS key for the security-hub Imported Findings SNS topic"
enable_key_rotation = true
alias = "alias/security-hub-sns"
policy = local.create_sns_topic ? data.aws_iam_policy_document.sns_kms_key_policy[0].json : ""
context = module.this.context
}
data "aws_iam_policy_document" "sns_kms_key_policy" {
count = local.create_sns_topic ? 1 : 0
policy_id = "EventBridgeEncryptUsingKey"
statement {
effect = "Allow"
actions = [
"kms:*"
]
resources = ["*"]
principals {
type = "AWS"
identifiers = ["arn:${one(data.aws_partition.this[*].partition)}:iam::${one(data.aws_caller_identity.this[*].account_id)}:root"]
}
}
statement {
effect = "Allow"
actions = [
"kms:Decrypt",
"kms:GenerateDataKey"
]
resources = ["*"]
principals {
type = "Service"
identifiers = ["events.amazonaws.com"]
}
}
}
module "sns_topic" {
source = "cloudposse/sns-topic/aws"
version = "0.21.0"
count = local.create_sns_topic ? 1 : 0
attributes = ["securityhub"]
subscribers = var.subscribers
sqs_dlq_enabled = false
kms_master_key_id = local.create_sns_topic ? module.sns_kms_key[0].alias_name : ""
allowed_aws_services_for_sns_published = ["events.amazonaws.com"]
context = module.this.context
}
module "imported_findings_label" {
source = "cloudposse/label/null"
version = "0.25.0"
attributes = ["securityhub-imported-findings"]
context = module.this.context
}
resource "aws_cloudwatch_event_rule" "imported_findings" {
count = local.enable_notifications ? 1 : 0
name = module.imported_findings_label.id
description = "SecurityHubEvent - Imported Findings"
tags = module.this.tags
event_pattern = jsonencode(
{
"source" : [
"aws.securityhub"
],
"detail-type" : [
var.cloudwatch_event_rule_pattern_detail_type
]
}
)
}
resource "aws_cloudwatch_event_target" "imported_findings" {
count = local.enable_notifications ? 1 : 0
rule = aws_cloudwatch_event_rule.imported_findings[0].name
arn = local.imported_findings_notification_arn
}