0

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!

sp0iler
  • 33
  • 1
  • 7
  • Sadly your question is not clear. Does your code result in errors? If yes, what errors? In other words, what's wrong with your code? – Marcin Dec 24 '21 at 01:48
  • @Marcin, hte code do not run. Terraforms says that ```count.index is 0 │ │ var.eventBuses is map of list of string with 2 elements``` – sp0iler Dec 24 '21 at 18:03

0 Answers0