0

I am working with an eventbridge rule that runs daily and triggers an ECS task definition as the eventbridge target (cloudwatch-event target). In my terraform script, I'm trying to pass a parameter using eventbridge input variable to the task definition.

This is what I currently have:

resource "aws_cloudwatch_event_target" "target" {
  rule      = var.rule_name
  target_id = var.target_id
  arn       = var.target_arn
  role_arn  = var.role_arn
  input     = jsonencode(
    {
      start : "10h15",
      end   : "12h"
  })
}

output "eventbridge_inputs" {
  value = module.event-bridge.*.input
}

Then in my task-definition, I'm trying to do something like this:

module "ecs_task_definition" {
  source              = "../../"
  name                = "var.name
  ...
  task_container_command = ["python", "-m", "app", lookup(module.event-bridge.eventbridge_inputs, "start", "10h"), lookup(module.event-bridge.eventbridge_inputs, "end", "12h")]

I'm running into some type errors because of the lookup but I'm pretty sure it's not the most elegant way to do this. I dont think input_transformer is a good option for me here because I'm not receive these parameters, I really want to provide them to ecs using eventbridge. I found some relevant solutions about it in python but nothing related to terraform Any ideas?

Alex
  • 389
  • 4
  • 21
  • 2
    "some type errors " - what errors exactly? – Marcin Nov 24 '21 at 04:40
  • Errors like this: Error: Unsupported attribute │ on ecs.tf line 78, in module "ecs_task_definition": │ 78: lookup(module.event-bridge.eventbridge_inputs, "start", "10h"), lookup(module.event-bridge.eventbridge_inputs, "end", ""), │ │ module.event-bridge is a list of object, known only after apply │ Can't access attributes on a list of objects. Did you mean to access an │ attribute for a specific element of the list, or across all elements of the │ list? However idk if the key issue is the type of what I've done in the lookup or if I'm using the input value wrong. – Alex Nov 24 '21 at 13:36

0 Answers0