README

eventbridge

Creates EventBridge event buses, rules, targets, API connections, API destinations, and Pipes with full support for FIFO patterns, dead-letter configs, ECS/Batch/SQS target types, and input transformation.

Custom event buses can have per-bus resource policies and event archives. Rules reference buses by map key (for buses created in this module) or by literal name (for the default bus or external buses). EventBridge Pipes support SQS, Kinesis, and DynamoDB stream sources with optional filter criteria.

Usage

module "eventbridge" {
  source  = "hcassc.jfrog.io/iac-terraform-modules-virtual/messaging/eventbridge/aws"
  version = "0.1.0"

  event_buses = {
    platform = {
      name               = "prod-platform-events"
      kms_key_identifier = module.kms.key_arn

      archive = {
        name           = "prod-platform-events-archive"
        retention_days = 30
      }
    }
  }

  rules = {
    order_created = {
      name          = "prod-order-created"
      event_bus_key = "platform"
      state         = "ENABLED"
      event_pattern = jsonencode({
        source      = ["com.example.orders"]
        detail-type = ["OrderCreated"]
      })
    }

    nightly_report = {
      name                = "prod-nightly-report"
      event_bus_name      = "default"
      schedule_expression = "cron(0 2 * * ? *)"
      role_arn            = aws_iam_role.eventbridge_scheduler.arn
    }
  }

  targets = {
    order_created_lambda = {
      rule_key      = "order_created"
      event_bus_key = "platform"
      target_id     = "OrderProcessorLambda"
      arn           = module.lambda.function_arns["order-processor"]

      dead_letter_config = {
        arn = module.sqs.queue_arns["eventbridge-dlq"]
      }

      retry_policy = {
        maximum_event_age_in_seconds = 3600
        maximum_retry_attempts       = 10
      }
    }

    nightly_report_ecs = {
      rule_key   = "nightly_report"
      target_id  = "NightlyReportTask"
      arn        = "arn:aws:ecs:us-east-1:123456789012:cluster/prod"
      role_arn   = aws_iam_role.eventbridge_ecs.arn

      ecs_target = {
        task_definition_arn = aws_ecs_task_definition.report.arn
        launch_type         = "FARGATE"
        task_count          = 1

        network_configuration = {
          subnets         = module.vpc.private_subnet_id_list
          security_groups = [module.security_groups.ids["ecs-tasks"]]
        }
      }
    }
  }

  pipes = {
    orders_to_platform = {
      name     = "prod-sqs-orders-to-platform-bus"
      role_arn = aws_iam_role.eventbridge_pipe.arn
      source   = module.sqs.queue_arns["orders"]
      target   = module.eventbridge.event_bus_arns["platform"]

      source_parameters = {
        sqs_queue_parameters = {
          batch_size = 10
        }
        filter_criteria = {
          filters = [
            { pattern = jsonencode({ body = { status = ["CONFIRMED"] } }) }
          ]
        }
      }

      target_parameters = {
        event_bridge_event_bus_parameters = {
          source      = "com.example.orders"
          detail_type = "OrderConfirmed"
        }
      }
    }
  }

  tags = {
    Environment = "prod"
    Team        = "platform"
  }
}

Requirements

Name Version
terraform ~> 1.5
aws ~> 6.50

Providers

Name Version
aws 6.50.0

Resources

Name Type
aws_cloudwatch_event_api_destination.this resource
aws_cloudwatch_event_archive.this resource
aws_cloudwatch_event_bus.this resource
aws_cloudwatch_event_bus_policy.this resource
aws_cloudwatch_event_connection.this resource
aws_cloudwatch_event_rule.this resource
aws_cloudwatch_event_target.this resource
aws_pipes_pipe.this resource

Inputs

Name Description Type Default Required
api_destinations Map of EventBridge API destination definitions map(object({ name = string description = optional(string, null) connection_key = string invocation_endpoint = string http_method = string invocation_rate_limit_per_second = optional(number, 300) })) {} no
connections Map of EventBridge API destination connection definitions map(object({ name = string description = optional(string, null) authorization_type = string auth_parameters = object({ api_key = optional(object({ key = string value = string }), null) basic = optional(object({ username = string password = string }), null) oauth = optional(object({ authorization_endpoint = string http_method = string client_parameters = object({ client_id = string client_secret = string }) }), null) }) })) {} no
event_buses Map of custom EventBridge event bus definitions (the default bus is always available) map(object({ name = string description = optional(string, null) kms_key_identifier = optional(string, null) policy = optional(string, null) archive = optional(object({ name = string description = optional(string, null) retention_days = optional(number, 0) event_pattern = optional(string, null) }), null) })) {} no
pipes Map of EventBridge Pipe definitions map(object({ name = string description = optional(string, null) role_arn = string source = string target = string state = optional(string, "RUNNING") source_parameters = optional(object({ filter_criteria = optional(object({ filters = list(object({ pattern = string })) }), null) sqs_queue_parameters = optional(object({ batch_size = optional(number, null) maximum_batching_window_in_seconds = optional(number, null) }), null) kinesis_stream_parameters = optional(object({ starting_position = optional(string, "LATEST") batch_size = optional(number, null) maximum_batching_window_in_seconds = optional(number, null) maximum_retry_attempts = optional(number, null) }), null) dynamodb_stream_parameters = optional(object({ starting_position = optional(string, "LATEST") batch_size = optional(number, null) maximum_batching_window_in_seconds = optional(number, null) maximum_retry_attempts = optional(number, null) }), null) }), null) target_parameters = optional(object({ input_template = optional(string, null) sqs_queue_parameters = optional(object({ message_group_id = optional(string, null) message_deduplication_id = optional(string, null) }), null) lambda_function_parameters = optional(object({ invocation_type = optional(string, "FIRE_AND_FORGET") }), null) eventbridge_event_bus_parameters = optional(object({ detail_type = optional(string, null) endpoint_id = optional(string, null) source = optional(string, null) time = optional(string, null) resources = optional(list(string), []) }), null) }), null) })) {} no
rules Map of EventBridge rule definitions map(object({ name = string description = optional(string, null) event_bus_key = optional(string, null) event_bus_name = optional(string, "default") state = optional(string, "ENABLED") event_pattern = optional(string, null) schedule_expression = optional(string, null) role_arn = optional(string, null) })) {} no
tags Resource tags to apply to all resources map(string) {} no
targets Map of EventBridge rule target definitions map(object({ rule_key = string target_id = string arn = string role_arn = optional(string, null) input = optional(string, null) input_path = optional(string, null) event_bus_key = optional(string, null) event_bus_name = optional(string, "default") input_transformer = optional(object({ input_paths = optional(map(string), {}) input_template = string }), null) dead_letter_config = optional(object({ arn = string }), null) retry_policy = optional(object({ maximum_event_age_in_seconds = optional(number, 86400) maximum_retry_attempts = optional(number, 185) }), null) batch_target = optional(object({ job_definition = string job_name = string array_size = optional(number, null) job_attempts = optional(number, null) }), null) ecs_target = optional(object({ task_definition_arn = string launch_type = optional(string, "FARGATE") platform_version = optional(string, null) task_count = optional(number, 1) group = optional(string, null) network_configuration = optional(object({ subnets = list(string) security_groups = optional(list(string), []) assign_public_ip = optional(bool, false) }), null) }), null) sqs_target = optional(object({ message_group_id = optional(string, null) }), null) })) {} no

Outputs

Name Description
api_destination_arns Map of API destination keys to EventBridge API destination ARNs
archive_arns Map of event bus keys to EventBridge archive ARNs
connection_arns Map of connection keys to EventBridge connection ARNs
connection_secret_arns Map of connection keys to Secrets Manager ARNs storing the connection credentials
event_bus_arns Map of event bus keys to EventBridge event bus ARNs
event_bus_names Map of event bus keys to EventBridge event bus names
pipe_arns Map of pipe keys to EventBridge Pipe ARNs
rule_arns Map of rule keys to EventBridge rule ARNs
rule_ids Map of rule keys to EventBridge rule IDs