From 07a2bc45b8f664eeae4eb858feb3392ea937112c Mon Sep 17 00:00:00 2001 From: Sven Lito Date: Tue, 28 Dec 2021 19:54:07 +0700 Subject: [PATCH 1/3] feat: event filter criteria --- README.md | 4 ++-- examples/event-source-mapping/main.tf | 17 +++++++++++++++++ examples/event-source-mapping/versions.tf | 3 +-- main.tf | 10 ++++++++++ versions.tf | 2 +- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3f28e15a..b4d61b02 100644 --- a/README.md +++ b/README.md @@ -592,7 +592,7 @@ Q4: What does this error mean - `"We currently do not support adding policies fo | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 0.13.1 | -| [aws](#requirement\_aws) | >= 3.61 | +| [aws](#requirement\_aws) | >= 3.69 | | [external](#requirement\_external) | >= 1 | | [local](#requirement\_local) | >= 1 | | [null](#requirement\_null) | >= 2 | @@ -601,7 +601,7 @@ Q4: What does this error mean - `"We currently do not support adding policies fo | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 3.61 | +| [aws](#provider\_aws) | >= 3.69 | | [external](#provider\_external) | >= 1 | | [local](#provider\_local) | >= 1 | | [null](#provider\_null) | >= 2 | diff --git a/examples/event-source-mapping/main.tf b/examples/event-source-mapping/main.tf index 9c2f3f24..1f5b464a 100644 --- a/examples/event-source-mapping/main.tf +++ b/examples/event-source-mapping/main.tf @@ -25,15 +25,32 @@ module "lambda_function" { event_source_mapping = { sqs = { event_source_arn = aws_sqs_queue.this.arn + filter_criteria = { + pattern = jsonencode({ + Temperature : [{ numeric : [">", 0, "<=", 100] }] + Location : ["Bangkok"] + }) + } } dynamodb = { event_source_arn = aws_dynamodb_table.this.stream_arn starting_position = "LATEST" destination_arn_on_failure = aws_sqs_queue.failure.arn + filter_criteria = { + pattern = jsonencode({ + eventName : ["INSERT"] + }) + } } kinesis = { event_source_arn = aws_kinesis_stream.this.arn starting_position = "LATEST" + filter_criteria = { + pattern = jsonencode({ + Temperature : [{ numeric : [">", 0, "<=", 100] }] + Location : ["Oslo"] + }) + } } mq = { event_source_arn = aws_mq_broker.this.arn diff --git a/examples/event-source-mapping/versions.tf b/examples/event-source-mapping/versions.tf index 3c075fa3..e0a9363b 100644 --- a/examples/event-source-mapping/versions.tf +++ b/examples/event-source-mapping/versions.tf @@ -2,8 +2,7 @@ terraform { required_version = ">= 0.13.1" required_providers { - aws = ">= 3.43" + aws = ">= 3.69" random = ">= 2" } } - diff --git a/main.tf b/main.tf index 551d8f61..e318abe8 100644 --- a/main.tf +++ b/main.tf @@ -253,4 +253,14 @@ resource "aws_lambda_event_source_mapping" "this" { uri = source_access_configuration.value["uri"] } } + + dynamic "filter_criteria" { + for_each = lookup(each.value, "filter_criteria", null) != null ? [true] : [] + + content { + filter { + pattern = each.value["filter_criteria"].pattern + } + } + } } diff --git a/versions.tf b/versions.tf index 509bccdf..36db8e58 100644 --- a/versions.tf +++ b/versions.tf @@ -2,7 +2,7 @@ terraform { required_version = ">= 0.13.1" required_providers { - aws = ">= 3.61" + aws = ">= 3.69" external = ">= 1" local = ">= 1" null = ">= 2" From 2600b493c8ada6011a16ae4f56c83c4ecc756bd5 Mon Sep 17 00:00:00 2001 From: Sven Lito Date: Wed, 29 Dec 2021 10:56:25 +0700 Subject: [PATCH 2/3] feat: event filter criteria --- examples/event-source-mapping/main.tf | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/event-source-mapping/main.tf b/examples/event-source-mapping/main.tf index 1f5b464a..dbefcd7b 100644 --- a/examples/event-source-mapping/main.tf +++ b/examples/event-source-mapping/main.tf @@ -27,8 +27,10 @@ module "lambda_function" { event_source_arn = aws_sqs_queue.this.arn filter_criteria = { pattern = jsonencode({ - Temperature : [{ numeric : [">", 0, "<=", 100] }] - Location : ["Bangkok"] + body : { + Temperature : [{ numeric : [">", 0, "<=", 100] }] + Location : ["Bangkok"] + } }) } } @@ -47,8 +49,10 @@ module "lambda_function" { starting_position = "LATEST" filter_criteria = { pattern = jsonencode({ - Temperature : [{ numeric : [">", 0, "<=", 100] }] - Location : ["Oslo"] + data : { + Temperature : [{ numeric : [">", 0, "<=", 100] }] + Location : ["Oslo"] + } }) } } From ba678fdd02ef96c72eeebdabf5665212c870b442 Mon Sep 17 00:00:00 2001 From: Sven Lito Date: Mon, 31 Jan 2022 16:18:09 +0700 Subject: [PATCH 3/3] feat: event filter criteria --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 85a652ea..dc509538 100644 --- a/main.tf +++ b/main.tf @@ -262,7 +262,7 @@ resource "aws_lambda_event_source_mapping" "this" { content { filter { - pattern = each.value["filter_criteria"].pattern + pattern = lookup(filter_criteria, "pattern", null) } } }