I’m using the below variable to create dynamic blocks within a aws_s3_bucket_notification
resource:
variable "event" {
type = list(object({
type = string,
target_arn = string,
s3_event = list(string)
}))
An example of expected inputs are:
event = [
{ type = "SQS", target_arn = "arn:aws:sqs:us-east-1:123456789000:my_queue", s3_event = ["s3:ObjectCreated:Put"] },
{ type = "SNS", target_arn = "arn:aws:sns:us-east-1:123456789000:my_topic", s3_event = ["s3:ObjectCreated:Post", "s3:ObjectRemoved:Delete"] },
{ type = "SNS", target_arn = "arn:aws:sns:us-east-1:123456789000:my_second_topic", s3_event = ["s3:ObjectCreated:Copy"] },
{ type = "lambda", target_arn = "arn:aws:lambda:us-east-1:123456789000:function:my_lambda", s3_event = ["s3:ObjectRestore:Completed"] },
{ type = "lambda", target_arn = "arn:aws:lambda:us-east-1:123456789000:function:another_lambda", s3_event = ["s3:ReducedRedundancyLostObject"] }
]
The dynamic blocks work as expected, but I would like to create a validation block, for this variable, to ensure that the s3_event
lists do not overlap because a terraform plan doesn’t catch this issue (a terraform apply will and this error will be generated: Configurations on the same bucket cannot share a common event type
).
Along with other google search results, I reviewed Best way to validate if a list(object) variable has unique attribute values in each object and I have been unable to add upon it to make this work → Ensure that there are no duplicate entries in any s3_event
list in any object.
I think the below is getting me close, but my tests were not successful.
for e in var.event.s3_event[*] : length(var.event[*].s3_event[*]) == [for x in e["s3_event"] :length(distinct(x[*]))]
Any help would be appreciated. Thank you in advance