-
Notifications
You must be signed in to change notification settings - Fork 0
/
event-notifications.tf
41 lines (31 loc) · 1.07 KB
/
event-notifications.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
data "aws_iam_policy_document" "queue" {
count = var.event_notification_config.target_type == "sqs" ? 1 : 0
statement {
effect = "Allow"
principals {
type = "*"
identifiers = ["*"]
}
actions = ["sqs:SendMessage"]
resources = ["arn:aws:sqs:*:*:${var.name}${var.event_notification_config.name_suffix}}"]
condition {
test = "ArnEquals"
variable = "aws:SourceArn"
values = [module.bucket.s3_bucket_arn]
}
}
}
resource "aws_sqs_queue" "queue" {
count = var.event_notification_config.target_type == "sqs" ? 1 : 0
name = replace("${var.name}${var.event_notification_config.name_suffix}", "/\\W+/", "_")
policy = data.aws_iam_policy_document.queue[0].json
}
resource "aws_s3_bucket_notification" "bucket_notification" {
count = var.event_notification_config.target_type == "sqs" ? 1 : 0
bucket = module.bucket.s3_bucket_id
queue {
queue_arn = aws_sqs_queue.queue[0].arn
events = var.event_notification_config.events
filter_prefix = var.event_notification_config.filter_prefix
}
}