I need to create dynamic EventBus that create specific Rules based on a object that wave a list inside each key.
My vars.tf file:
variable "bus_name" {
type = string
description = "Event Bus Main Name"
}
variable "bus_path" {
type = map(list(string))
description = "Event Bus Path"
default = {
"GupyEventBus" = [
"GupyApplications",
"GupyJobs",
]
"ConveniaEventBus" = [
"ConveniaAdmissions",
"ConveniaDismissals",
]
}
}
Thus the main.tf file is:
module eventbridge {
count = length(var.bus_paths)
source = "terraform-aws-modules/eventbridge/aws"
bus_name = var.bus_name
rules = {
orders = {
description = "Capture ${var.bus_paths[count.index]} data"
event_pattern = jsonencode({ "source" : ["/${var.bus_paths[count.index]}"] })
enabled = true
}
}
targets = {
orders = [
{
name = "send-orders-to-lambda"
arn = "My lambda arn"
}
]
}
tags = {
Name = var.bus_name
}
}
All this code is inside a module that i call in this way:
module "event-bridge" {
count = length(var.EventBus_Names)
source = "./modules/EventBridge"
bus_name = var.EventBus_Names[count.index]
}
Note that EventBus_Names
is another variable list that holds the same info that bus_paths keys.
I certainly sure that wave better ways to do this. Suggestions is appreciated!