Hi All
AWS v5.25.0
Terraform v1.5.7
variable "queues" {
type = list(object({
id = string,
}))
default = [
{ id = "1" },
]
}
resource "aws_sqs_queue" "queues" {
for_each = { for queue in var.queues: "${queue.id}.fifo" => queue }
name = "queue-${each.value.id}.fifo"
fifo_queue = true
}
resource "aws_sqs_queue_policy" "queue" {
for_each = aws_sqs_queue.queues
queue_url = each.value.id
policy = data.aws_iam_policy_document.queue-policy[each.key].json
}
data "aws_iam_policy_document" "queue-policy" {
for_each = aws_sqs_queue.queues
policy_id = each.value.name
statement {
sid = "__owner_statement"
effect = "Allow"
resources = [ each.value.arn ]
actions = [
"SQS:*",
]
principals {
identifiers = [ var.aws-account-id ]
type = "AWS"
}
}
}
When adding one more element to the “queues” (with id 2) variable terraform plan shows adding new changes related to the new queue (expected) BUT also changes to the current queue with id 1:
# aws_sqs_queue_policy.queue["1"] will be updated in-place
~ resource "aws_sqs_queue_policy" "queue" {
id = "<hidden>"
~ policy = jsonencode(
{
- Id = "queue-1.fifo"
- Statement = [
- {
- Action = "SQS:*"
- Effect = "Allow"
- Principal = {
- AWS = "<hidden>"
}
- Resource = "<hidden>"
- Sid = "__owner_statement"
}
]
- Version = "2012-10-17"
}
) -> (known after apply)
# (1 unchanged attribute hidden)