Skip to content

Commit

Permalink
fix(DMVP-5181): Add sqs event support
Browse files Browse the repository at this point in the history
  • Loading branch information
aramkarapetian committed Sep 23, 2024
1 parent ff09dc4 commit 5739859
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
41 changes: 41 additions & 0 deletions event-notifications.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,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:*:*:s3-event-notification-queue"]

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 = var.event-notification-config.queue_name
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
}
}
13 changes: 13 additions & 0 deletions tests/sqs-event-notifications/1-example.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module "private" {
source = "../.."

name = "dasmeta-dev-private"

event-notification-config = {
target_type = "sqs"
queue_name = "test"
filter_prefix = "test/"
events = ["s3:ObjectCreated:CompleteMultipartUpload"]
}
}

15 changes: 15 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,18 @@ variable "cors_rule" {
type = any
default = []
}

variable "event-notification-config" {
type = object({
target_type = string,
queue_name = string,
filter_prefix = string,
events = optional(list(string), ["s3:ObjectCreated:*"])
})
default = {
target_type = "null"
queue_name = "test"
filter_prefix = "test/"
events = ["s3:ObjectCreated:*"]
}
}

0 comments on commit 5739859

Please sign in to comment.