-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnotification.tf
47 lines (36 loc) · 1.42 KB
/
notification.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
data "aws_iam_policy_document" "sns_codestar_policy" {
count = var.codestar_notifications_target_arn == "" ? 1 : 0
statement {
actions = ["sns:Publish"]
principals {
type = "Service"
identifiers = ["codestar-notifications.amazonaws.com"]
}
resources = [aws_sns_topic.notifications[count.index].arn]
}
}
resource "aws_codestarnotifications_notification_rule" "notification" {
detail_type = var.codestar_notifications_detail_type
event_type_ids = var.codestar_notifications_event_type_ids
name = "${var.service_name}-notifications-${data.aws_region.current.name}"
resource = aws_codepipeline.codepipeline.arn
tags = merge(var.tags, {
tf_module = basename(path.module)
})
target {
address = var.codestar_notifications_target_arn == "" ? aws_sns_topic.notifications[0].arn : var.codestar_notifications_target_arn
}
}
resource "aws_sns_topic" "notifications" {
count = var.codestar_notifications_target_arn == "" ? 1 : 0
name = "${var.service_name}-notifications"
kms_master_key_id = var.codestar_notification_kms_master_key_id
tags = merge(var.tags, {
tf_module = basename(path.module)
})
}
resource "aws_sns_topic_policy" "notifications" {
count = var.codestar_notifications_target_arn == "" ? 1 : 0
arn = aws_sns_topic.notifications[count.index].arn
policy = data.aws_iam_policy_document.sns_codestar_policy[count.index].json
}