Skip to content

Commit 78ac5d7

Browse files
authored
fix: Allow API destinations to reuse connections (#108)
1 parent 073a595 commit 78ac5d7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

examples/with-api-destination/main.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ module "eventbridge" {
2424
event_pattern = jsonencode({ "source" : ["myapp.orders"] })
2525
state = "ENABLED" # conflicts with enabled which is deprecated
2626
}
27+
refunds = {
28+
description = "Capture all refund data"
29+
event_pattern = jsonencode({ "source" : ["myapp.refunds"] })
30+
state = "ENABLED" # conflicts with enabled which is deprecated
31+
}
2732
}
2833

2934
targets = {
@@ -39,6 +44,13 @@ module "eventbridge" {
3944
attach_role_arn = true
4045
}
4146
]
47+
refunds = [
48+
{
49+
name = "send-refunds-to-github"
50+
destination = "refunds_github"
51+
attach_role_arn = true
52+
}
53+
]
4254
}
4355

4456
connections = {
@@ -152,6 +164,14 @@ module "eventbridge" {
152164
http_method = "POST"
153165
invocation_rate_limit_per_second = 20
154166
}
167+
# reuse github connection
168+
refunds_github = {
169+
description = "my refunds to github endpoint"
170+
invocation_endpoint = "https://smee.io/QaM356V2p1PFFZS"
171+
http_method = "POST"
172+
invocation_rate_limit_per_second = 20
173+
connection_name = "github"
174+
}
155175
}
156176
}
157177

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ resource "aws_cloudwatch_event_api_destination" "this" {
425425
invocation_endpoint = each.value.invocation_endpoint
426426
http_method = each.value.http_method
427427
invocation_rate_limit_per_second = lookup(each.value, "invocation_rate_limit_per_second", null)
428-
connection_arn = aws_cloudwatch_event_connection.this[each.value.name].arn
428+
connection_arn = try(aws_cloudwatch_event_connection.this[each.value.connection_name].arn, aws_cloudwatch_event_connection.this[each.value.name].arn)
429429
}
430430

431431
resource "aws_scheduler_schedule_group" "this" {

0 commit comments

Comments
 (0)