Hello maxb thank you for the interest in the issue, following is the whole repro of the issue.
I’ve created 3 queues:
- lt-errorreport
- lt-jobresults
- lt-clips
and i’ve created a bucket lt-tf-test-bucket
and i’m going to use the following tf code to create bucket notifications to the first 2 queues i previously created:
provider "aws" {
profile = "<REDACTED>"
region = "us-west-1"
}
locals {
sqs_queues = {
"lt-errorreport" = "errors"
"lt-jobresults" = "results"
}
}
data "aws_sqs_queue" "sqs_queues" {
for_each = local.sqs_queues
name = each.key
}
resource "aws_sqs_queue_policy" "allow_bucket_sqs" {
for_each = data.aws_sqs_queue.sqs_queues
queue_url = each.value.url
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "sqs:SendMessage",
"Resource": "${each.value.arn}",
"Condition": {
"ArnEquals": { "aws:SourceArn": "arn:aws:s3:::lt-tf-test-bucket" }
}
}
]
}
POLICY
}
resource "aws_s3_bucket_notification" "bucket_notification" {
count = length(data.aws_sqs_queue.sqs_queues) != 0 ? 1 : 0
bucket = "lt-tf-test-bucket"
dynamic "queue" {
for_each = data.aws_sqs_queue.sqs_queues
content {
queue_arn = queue.value.arn
events = ["s3:ObjectCreated:*"]
filter_prefix = local.sqs_queues[queue.value.name]
}
}
}
here is the initial plan that i’m going to apply:
terraform plan -out tfplan
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_s3_bucket_notification.bucket_notification[0] will be created
+ resource "aws_s3_bucket_notification" "bucket_notification" {
+ bucket = "lt-tf-test-bucket"
+ eventbridge = false
+ id = (known after apply)
+ queue {
+ events = [
+ "s3:ObjectCreated:*",
]
+ filter_prefix = "errors"
+ id = (known after apply)
+ queue_arn = "arn:aws:sqs:us-west-1:<REDACTED>:lt-errorreport"
}
+ queue {
+ events = [
+ "s3:ObjectCreated:*",
]
+ filter_prefix = "results"
+ id = (known after apply)
+ queue_arn = "arn:aws:sqs:us-west-1:<REDACTED>:lt-jobresults"
}
}
# aws_sqs_queue_policy.allow_bucket_sqs["lt-errorreport"] will be created
+ resource "aws_sqs_queue_policy" "allow_bucket_sqs" {
+ id = (known after apply)
+ policy = jsonencode(
{
+ Statement = [
+ {
+ Action = "sqs:SendMessage"
+ Condition = {
+ ArnEquals = {
+ aws:SourceArn = "arn:aws:s3:::lt-tf-test-bucket"
}
}
+ Effect = "Allow"
+ Principal = "*"
+ Resource = "arn:aws:sqs:us-west-1:<REDACTED>:lt-errorreport"
},
]
+ Version = "2012-10-17"
}
)
+ queue_url = "https://sqs.us-west-1.amazonaws.com/<REDACTED>/lt-errorreport"
}
# aws_sqs_queue_policy.allow_bucket_sqs["lt-jobresults"] will be created
+ resource "aws_sqs_queue_policy" "allow_bucket_sqs" {
+ id = (known after apply)
+ policy = jsonencode(
{
+ Statement = [
+ {
+ Action = "sqs:SendMessage"
+ Condition = {
+ ArnEquals = {
+ aws:SourceArn = "arn:aws:s3:::lt-tf-test-bucket"
}
}
+ Effect = "Allow"
+ Principal = "*"
+ Resource = "arn:aws:sqs:us-west-1:<REDACTED>:lt-jobresults"
},
]
+ Version = "2012-10-17"
}
)
+ queue_url = "https://sqs.us-west-1.amazonaws.com/<REDACTED>/lt-jobresults"
}
Plan: 3 to add, 0 to change, 0 to destroy.
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Saved the plan to: tfplan
To perform exactly these actions, run the following command to apply:
terraform apply "tfplan"
x:queues ltagliamonte$ terraform apply "tfplan"
aws_sqs_queue_policy.allow_bucket_sqs["lt-errorreport"]: Creating...
aws_s3_bucket_notification.bucket_notification[0]: Creating...
aws_sqs_queue_policy.allow_bucket_sqs["lt-jobresults"]: Creating...
aws_s3_bucket_notification.bucket_notification[0]: Creation complete after 1s [id=lt-tf-test-bucket]
aws_sqs_queue_policy.allow_bucket_sqs["lt-jobresults"]: Still creating... [10s elapsed]
aws_sqs_queue_policy.allow_bucket_sqs["lt-errorreport"]: Still creating... [10s elapsed]
aws_sqs_queue_policy.allow_bucket_sqs["lt-errorreport"]: Still creating... [20s elapsed]
aws_sqs_queue_policy.allow_bucket_sqs["lt-jobresults"]: Still creating... [20s elapsed]
aws_sqs_queue_policy.allow_bucket_sqs["lt-errorreport"]: Creation complete after 26s [id=https://sqs.us-west-1.amazonaws.com/<REDACTED>/lt-errorreport]
aws_sqs_queue_policy.allow_bucket_sqs["lt-jobresults"]: Creation complete after 26s [id=https://sqs.us-west-1.amazonaws.com/<REDACTED>/lt-jobresults]
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
after applied i’ve changed the local variable to be:
locals {
sqs_queues = {
"lt-errorreport" = "errors"
"lt-jobresults" = "results"
"lt-clips" = "clips"
}
}
here is the plan i get now, with the shifted resources:
terraform plan -out tfplan
aws_sqs_queue_policy.allow_bucket_sqs["lt-jobresults"]: Refreshing state... [id=https://sqs.us-west-1.amazonaws.com/082346306812/lt-jobresults]
aws_sqs_queue_policy.allow_bucket_sqs["lt-errorreport"]: Refreshing state... [id=https://sqs.us-west-1.amazonaws.com/082346306812/lt-errorreport]
aws_s3_bucket_notification.bucket_notification[0]: Refreshing state... [id=lt-tf-test-bucket]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
~ update in-place
Terraform will perform the following actions:
# aws_s3_bucket_notification.bucket_notification[0] will be updated in-place
~ resource "aws_s3_bucket_notification" "bucket_notification" {
id = "lt-tf-test-bucket"
# (2 unchanged attributes hidden)
~ queue {
~ filter_prefix = "errors" -> "clips"
id = "tf-s3-queue-20230226233626104600000001"
~ queue_arn = "arn:aws:sqs:us-west-1:082346306812:lt-errorreport" -> "arn:aws:sqs:us-west-1:082346306812:lt-clips"
# (1 unchanged attribute hidden)
}
~ queue {
~ filter_prefix = "results" -> "errors"
id = "tf-s3-queue-20230226233626104600000002"
~ queue_arn = "arn:aws:sqs:us-west-1:082346306812:lt-jobresults" -> "arn:aws:sqs:us-west-1:082346306812:lt-errorreport"
# (1 unchanged attribute hidden)
}
+ queue {
+ events = [
+ "s3:ObjectCreated:*",
]
+ filter_prefix = "results"
+ queue_arn = "arn:aws:sqs:us-west-1:082346306812:lt-jobresults"
}
}
# aws_sqs_queue_policy.allow_bucket_sqs["lt-clips"] will be created
+ resource "aws_sqs_queue_policy" "allow_bucket_sqs" {
+ id = (known after apply)
+ policy = jsonencode(
{
+ Statement = [
+ {
+ Action = "sqs:SendMessage"
+ Condition = {
+ ArnEquals = {
+ aws:SourceArn = "arn:aws:s3:::lt-tf-test-bucket"
}
}
+ Effect = "Allow"
+ Principal = "*"
+ Resource = "arn:aws:sqs:us-west-1:082346306812:lt-clips"
},
]
+ Version = "2012-10-17"
}
)
+ queue_url = "https://sqs.us-west-1.amazonaws.com/082346306812/lt-clips"
}
Plan: 1 to add, 1 to change, 0 to destroy.