Terraform -Multiple aws_s3_bucket_notification triggers on the same bucket

I need to create a multiple trigger for an S3 bucket.
This works fine when the bucket does not already have a trigger which was the case for all environments apart from production. When we deployed production we saw that the trigger which was already present on the bucket got deleted. We need both triggers. I was able to add another trigger manually but through terraform its not working.

anybody got any solution to this issue ? I got the same issue while creating multiple s3_bucket_notification for same bucket.

I got the solution for this issue. Here is my requirements . I have to create multiple SQS s3_event_notification for the same bucket using different prefix.

Ex:

{
name : bucket-1
prefix : Test1/
},
{
name: bucket-1
prefix: Test2/
}

To achieve this , add multiple queue. for more information check the document . Terraform Registry

Ex: ```
queue {
id = “image-upload-event”
queue_arn = aws_sqs_queue.queue.arn
events = [“s3:ObjectCreated:*”]
filter_prefix = “images/”
}

queue {
id = “video-upload-event”
queue_arn = aws_sqs_queue.queue.arn
events = [“s3:ObjectCreated:*”]
filter_prefix = “videos/”
}



Note : Use dynamic block to iterate to create multiple queue. Here is an example I did it in my requirement. Iterate the source bucket from the main module . 


Ex: 

data "aws_s3_bucket" "s3_bucket" {
  bucket = var.SourceBucket
}

resource "aws_s3_bucket_notification" "bucket_notification" {
  bucket = data.aws_s3_bucket.s3_bucket.id
  dynamic "queue" {
    for_each = var.filter_prefix
    content {
      id = "${var.SourceBucket}-${queue.key}"
      queue_arn     = var.sqs_queue_arn
      events        = ["s3:ObjectCreated:*"]
      filter_prefix = queue.value
    }
  }
 }


I hope it helps,
Khirod