Skip to content

Commit

Permalink
Merge pull request #22 from dasmeta/DMVP-5181
Browse files Browse the repository at this point in the history
fix(DMVP-5181): Add sqs event support
  • Loading branch information
aghamyan44 authored Sep 23, 2024
2 parents 090cf74 + f73d6be commit 4a03aad
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:*:*:${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
}
}
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"
name_suffix = "event"
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, // Target type for the S3 event notification, can be "sqs" or "null". Other target types can be implemented in the future.
name_suffix = string, // Suffix to add to the target name.
filter_prefix = string, // Prefix to filter object key names for the event notification.
events = optional(list(string), ["s3:ObjectCreated:*"]) // List of S3 events that trigger the notification. Defaults to "s3:ObjectCreated:*".
})
default = {
target_type = "null"
name_suffix = "event"
filter_prefix = "test/"
events = ["s3:ObjectCreated:*"]
}
}

0 comments on commit 4a03aad

Please sign in to comment.