From 78ac5d7711b2715c93f69632a38c6e508e8f7cdd Mon Sep 17 00:00:00 2001 From: Melissa Greenbaum <69476188+magreenbaum@users.noreply.github.com> Date: Mon, 5 Feb 2024 02:58:28 -0500 Subject: [PATCH] fix: Allow API destinations to reuse connections (#108) --- examples/with-api-destination/main.tf | 20 ++++++++++++++++++++ main.tf | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/examples/with-api-destination/main.tf b/examples/with-api-destination/main.tf index 457f257..ef038ed 100644 --- a/examples/with-api-destination/main.tf +++ b/examples/with-api-destination/main.tf @@ -24,6 +24,11 @@ module "eventbridge" { event_pattern = jsonencode({ "source" : ["myapp.orders"] }) state = "ENABLED" # conflicts with enabled which is deprecated } + refunds = { + description = "Capture all refund data" + event_pattern = jsonencode({ "source" : ["myapp.refunds"] }) + state = "ENABLED" # conflicts with enabled which is deprecated + } } targets = { @@ -39,6 +44,13 @@ module "eventbridge" { attach_role_arn = true } ] + refunds = [ + { + name = "send-refunds-to-github" + destination = "refunds_github" + attach_role_arn = true + } + ] } connections = { @@ -152,6 +164,14 @@ module "eventbridge" { http_method = "POST" invocation_rate_limit_per_second = 20 } + # reuse github connection + refunds_github = { + description = "my refunds to github endpoint" + invocation_endpoint = "https://smee.io/QaM356V2p1PFFZS" + http_method = "POST" + invocation_rate_limit_per_second = 20 + connection_name = "github" + } } } diff --git a/main.tf b/main.tf index e0c173d..838e50b 100644 --- a/main.tf +++ b/main.tf @@ -425,7 +425,7 @@ resource "aws_cloudwatch_event_api_destination" "this" { invocation_endpoint = each.value.invocation_endpoint http_method = each.value.http_method invocation_rate_limit_per_second = lookup(each.value, "invocation_rate_limit_per_second", null) - connection_arn = aws_cloudwatch_event_connection.this[each.value.name].arn + connection_arn = try(aws_cloudwatch_event_connection.this[each.value.connection_name].arn, aws_cloudwatch_event_connection.this[each.value.name].arn) } resource "aws_scheduler_schedule_group" "this" {