# 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

```hcl
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"
  }
}
```

<!-- BEGIN_TF_DOCS — DO NOT EDIT BELOW THIS LINE -->
## Requirements

| Name | Version |
| ---- | ------- |
| <a name="requirement_terraform"></a> [terraform](#requirement_terraform) | ~> 1.5 |
| <a name="requirement_aws"></a> [aws](#requirement_aws) | ~> 6.50 |

## Providers

| Name | Version |
| ---- | ------- |
| <a name="provider_aws"></a> [aws](#provider_aws) | 6.50.0 |

## Resources

| Name | Type |
| ---- | ---- |
| [aws_cloudwatch_event_api_destination.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_api_destination) | resource |
| [aws_cloudwatch_event_archive.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_archive) | resource |
| [aws_cloudwatch_event_bus.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_bus) | resource |
| [aws_cloudwatch_event_bus_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_bus_policy) | resource |
| [aws_cloudwatch_event_connection.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_connection) | resource |
| [aws_cloudwatch_event_rule.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_rule) | resource |
| [aws_cloudwatch_event_target.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource |
| [aws_pipes_pipe.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/pipes_pipe) | resource |

## Inputs

| Name | Description | Type | Default | Required |
| ---- | ----------- | ---- | ------- | :------: |
| <a name="input_api_destinations"></a> [api_destinations](#input_api_destinations) | Map of EventBridge API destination definitions | <pre>map(object({<br/>    name                             = string<br/>    description                      = optional(string, null)<br/>    connection_key                   = string<br/>    invocation_endpoint              = string<br/>    http_method                      = string<br/>    invocation_rate_limit_per_second = optional(number, 300)<br/>  }))</pre> | `{}` | no |
| <a name="input_connections"></a> [connections](#input_connections) | Map of EventBridge API destination connection definitions | <pre>map(object({<br/>    name               = string<br/>    description        = optional(string, null)<br/>    authorization_type = string<br/><br/>    auth_parameters = object({<br/>      api_key = optional(object({<br/>        key   = string<br/>        value = string<br/>      }), null)<br/>      basic = optional(object({<br/>        username = string<br/>        password = string<br/>      }), null)<br/>      oauth = optional(object({<br/>        authorization_endpoint = string<br/>        http_method            = string<br/>        client_parameters = object({<br/>          client_id     = string<br/>          client_secret = string<br/>        })<br/>      }), null)<br/>    })<br/>  }))</pre> | `{}` | no |
| <a name="input_event_buses"></a> [event_buses](#input_event_buses) | Map of custom EventBridge event bus definitions (the default bus is always available) | <pre>map(object({<br/>    name               = string<br/>    description        = optional(string, null)<br/>    kms_key_identifier = optional(string, null)<br/><br/>    policy = optional(string, null)<br/><br/>    archive = optional(object({<br/>      name           = string<br/>      description    = optional(string, null)<br/>      retention_days = optional(number, 0)<br/>      event_pattern  = optional(string, null)<br/>    }), null)<br/>  }))</pre> | `{}` | no |
| <a name="input_pipes"></a> [pipes](#input_pipes) | Map of EventBridge Pipe definitions | <pre>map(object({<br/>    name        = string<br/>    description = optional(string, null)<br/>    role_arn    = string<br/>    source      = string<br/>    target      = string<br/>    state       = optional(string, "RUNNING")<br/><br/>    source_parameters = optional(object({<br/>      filter_criteria = optional(object({<br/>        filters = list(object({<br/>          pattern = string<br/>        }))<br/>      }), null)<br/>      sqs_queue_parameters = optional(object({<br/>        batch_size                         = optional(number, null)<br/>        maximum_batching_window_in_seconds = optional(number, null)<br/>      }), null)<br/>      kinesis_stream_parameters = optional(object({<br/>        starting_position                  = optional(string, "LATEST")<br/>        batch_size                         = optional(number, null)<br/>        maximum_batching_window_in_seconds = optional(number, null)<br/>        maximum_retry_attempts             = optional(number, null)<br/>      }), null)<br/>      dynamodb_stream_parameters = optional(object({<br/>        starting_position                  = optional(string, "LATEST")<br/>        batch_size                         = optional(number, null)<br/>        maximum_batching_window_in_seconds = optional(number, null)<br/>        maximum_retry_attempts             = optional(number, null)<br/>      }), null)<br/>    }), null)<br/><br/>    target_parameters = optional(object({<br/>      input_template = optional(string, null)<br/>      sqs_queue_parameters = optional(object({<br/>        message_group_id         = optional(string, null)<br/>        message_deduplication_id = optional(string, null)<br/>      }), null)<br/>      lambda_function_parameters = optional(object({<br/>        invocation_type = optional(string, "FIRE_AND_FORGET")<br/>      }), null)<br/>      eventbridge_event_bus_parameters = optional(object({<br/>        detail_type = optional(string, null)<br/>        endpoint_id = optional(string, null)<br/>        source      = optional(string, null)<br/>        time        = optional(string, null)<br/>        resources   = optional(list(string), [])<br/>      }), null)<br/>    }), null)<br/>  }))</pre> | `{}` | no |
| <a name="input_rules"></a> [rules](#input_rules) | Map of EventBridge rule definitions | <pre>map(object({<br/>    name                = string<br/>    description         = optional(string, null)<br/>    event_bus_key       = optional(string, null)<br/>    event_bus_name      = optional(string, "default")<br/>    state               = optional(string, "ENABLED")<br/>    event_pattern       = optional(string, null)<br/>    schedule_expression = optional(string, null)<br/>    role_arn            = optional(string, null)<br/>  }))</pre> | `{}` | no |
| <a name="input_tags"></a> [tags](#input_tags) | Resource tags to apply to all resources | `map(string)` | `{}` | no |
| <a name="input_targets"></a> [targets](#input_targets) | Map of EventBridge rule target definitions | <pre>map(object({<br/>    rule_key       = string<br/>    target_id      = string<br/>    arn            = string<br/>    role_arn       = optional(string, null)<br/>    input          = optional(string, null)<br/>    input_path     = optional(string, null)<br/>    event_bus_key  = optional(string, null)<br/>    event_bus_name = optional(string, "default")<br/><br/>    input_transformer = optional(object({<br/>      input_paths    = optional(map(string), {})<br/>      input_template = string<br/>    }), null)<br/><br/>    dead_letter_config = optional(object({<br/>      arn = string<br/>    }), null)<br/><br/>    retry_policy = optional(object({<br/>      maximum_event_age_in_seconds = optional(number, 86400)<br/>      maximum_retry_attempts       = optional(number, 185)<br/>    }), null)<br/><br/>    batch_target = optional(object({<br/>      job_definition = string<br/>      job_name       = string<br/>      array_size     = optional(number, null)<br/>      job_attempts   = optional(number, null)<br/>    }), null)<br/><br/>    ecs_target = optional(object({<br/>      task_definition_arn = string<br/>      launch_type         = optional(string, "FARGATE")<br/>      platform_version    = optional(string, null)<br/>      task_count          = optional(number, 1)<br/>      group               = optional(string, null)<br/>      network_configuration = optional(object({<br/>        subnets          = list(string)<br/>        security_groups  = optional(list(string), [])<br/>        assign_public_ip = optional(bool, false)<br/>      }), null)<br/>    }), null)<br/><br/>    sqs_target = optional(object({<br/>      message_group_id = optional(string, null)<br/>    }), null)<br/>  }))</pre> | `{}` | no |

## Outputs

| Name | Description |
| ---- | ----------- |
| <a name="output_api_destination_arns"></a> [api_destination_arns](#output_api_destination_arns) | Map of API destination keys to EventBridge API destination ARNs |
| <a name="output_archive_arns"></a> [archive_arns](#output_archive_arns) | Map of event bus keys to EventBridge archive ARNs |
| <a name="output_connection_arns"></a> [connection_arns](#output_connection_arns) | Map of connection keys to EventBridge connection ARNs |
| <a name="output_connection_secret_arns"></a> [connection_secret_arns](#output_connection_secret_arns) | Map of connection keys to Secrets Manager ARNs storing the connection credentials |
| <a name="output_event_bus_arns"></a> [event_bus_arns](#output_event_bus_arns) | Map of event bus keys to EventBridge event bus ARNs |
| <a name="output_event_bus_names"></a> [event_bus_names](#output_event_bus_names) | Map of event bus keys to EventBridge event bus names |
| <a name="output_pipe_arns"></a> [pipe_arns](#output_pipe_arns) | Map of pipe keys to EventBridge Pipe ARNs |
| <a name="output_rule_arns"></a> [rule_arns](#output_rule_arns) | Map of rule keys to EventBridge rule ARNs |
| <a name="output_rule_ids"></a> [rule_ids](#output_rule_ids) | Map of rule keys to EventBridge rule IDs |
<!-- END_TF_DOCS — DO NOT EDIT ABOVE THIS LINE -->
