Created
June 27, 2023 16:10
-
-
Save alexjeen/799c90704ef955f1906d1ada6a69699d to your computer and use it in GitHub Desktop.
Using the EventBridge modules multiple times
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "env_level" { | |
description = "Environment level" | |
default = "dev" | |
} | |
module "eventbridge_price" { | |
source = "terraform-aws-modules/eventbridge/aws" | |
create_bus = false | |
create_connections = true | |
create_api_destinations = true | |
attach_api_destination_policy = true | |
rules = { | |
"test_room_price_${var.env_level}" = { | |
description = "Trigger test room price cron" | |
schedule_expression = "cron(20 4 * * ? *)" | |
enabled = true | |
event_pattern = null | |
} | |
} | |
targets = { | |
"test_room_price_${var.env_level}" = [ | |
{ | |
name = "send-request-to-test-room-price-${var.env_level}" | |
destination = "test_room_price_${var.env_level}" | |
attach_role_arn = true | |
} | |
] | |
} | |
connections = { | |
"test_room_price_${var.env_level}" = { | |
authorization_type = "API_KEY" | |
auth_parameters = { | |
api_key = { | |
key = "Authorization" | |
value = "Bearer testtoken" | |
} | |
} | |
} | |
} | |
api_destinations = { | |
"test_room_price_${var.env_level}" = { | |
description = "my test room price endpoint" | |
invocation_endpoint = "https://example.com/generate_cts/*" | |
http_method = "POST" | |
invocation_rate_limit_per_second = 10 | |
} | |
} | |
} | |
module "eventbridge_details" { | |
source = "terraform-aws-modules/eventbridge/aws" | |
create_bus = false | |
create_connections = true | |
create_api_destinations = true | |
attach_api_destination_policy = true | |
rules = { | |
"test_room_details_${var.env_level}" = { | |
description = "Trigger test room details cron" | |
schedule_expression = "cron(50 3 * * ? *)" | |
enabled = true | |
event_pattern = null | |
} | |
} | |
targets = { | |
"test_room_details_${var.env_level}" = [ | |
{ | |
name = "send-request-to-test-room-details-${var.env_level}" | |
destination = "test_room_details_${var.env_level}" | |
attach_role_arn = true | |
} | |
] | |
} | |
connections = { | |
"test_room_details_${var.env_level}" = { | |
authorization_type = "API_KEY" | |
auth_parameters = { | |
api_key = { | |
key = "Authorization" | |
value = "Bearer testtoken" | |
} | |
} | |
} | |
} | |
api_destinations = { | |
"test_room_details_${var.env_level}" = { | |
description = "XXX" | |
invocation_endpoint = "http://example.com/generate_cts/*" | |
http_method = "POST" | |
invocation_rate_limit_per_second = 10 | |
} | |
} | |
} |
I really appreciate your effort, sir. Thanks a lot 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You shouldnt really use the module from the GIT repo like that. It will cause issues later on (with your statefile) its best to use it like I mentioned:
You can use a variable for the connection, like this, you can then just re-use it for the connections part so you can manage it in a central place (because how this module works, it maps by name, it needs to be there for the connection):
The solution should be scalable.