Terraform AWS Modules EventBridge AWS Deep Dive

AWS EventBridge is a serverless event bus service that allows you to listen to events from your applications, supported third-party applications, and AWS services. It simplifies building event-driven architectures by serving as the central event hub and enabling applications to publish, subscribe to, and react to events in near real-time.

The terraform-aws-modules/terraform-aws-eventbridge module provides a comprehensive Terraform abstraction for AWS EventBridge resources. It creates AWS EventBridge Resources (bus, rules, targets, permissions, connections, destinations, pipes, schedules and schedule groups). It also supports attaching resources to an existing EventBridge bus, support AWS EventBridge Archives and Replays, conditional creation for many types of resources, and support IAM policy attachments and various ways to create and attach additional policies.

The most common use-case which creates custom bus, logging, rules and targets.

Module Overview and Capabilities

The module targets the most common use-case which creates custom bus, rules and targets.

Capabilities covered by the module include:

  • Creates AWS EventBridge Resources (bus, rules, targets, permissions, connections, destinations, pipes, schedules and schedule groups)
  • Attach resources to an existing EventBridge bus
  • Support AWS EventBridge Archives and Replays
  • Conditional creation for many types of resources
  • Support IAM policy attachments and various ways to create and attach additional policies

The module is designed for both greenfield EventBridge deployments and incremental enhancements to existing buses. Conditional creation flags allow selective provisioning of rules, targets, archives, permissions, and logging.

Core Resource Model

The module centers on a custom bus definition with associated rules and targets.

A typical bus with rules and targets is expressed as:

hcl module "eventbridge" { source = "terraform-aws-modules/eventbridge/aws" bus_name = "my-bus" rules = { orders = { description = "Capture all order data" event_pattern = jsonencode({ "source" : ["myapp.orders"] }) enabled = true } } targets = { orders = [ { name = "send-orders-to-sqs" arn = aws_sqs_queue.queue.arn dead_letter_arn = aws_sqs_queue.dlq.arn }, { name = "send-orders-to-kinesis" arn = aws_kinesis_stream.this.arn dead_letter_arn = aws_sqs_queue.dlq.arn input_transformer = local.kinesis_input_transformer }, { name = "log-orders-to-cloudwatch" arn = aws_cloudwatch_log_group.this.arn } ] } tags = { Name = "my-bus" } }

The same module can be invoked to create only a bus with tags:

hcl module "eventbridge" { source = "terraform-aws-modules/eventbridge/aws" bus_name = "my-bus" tags = { Name = "my-bus" } }

When targets are not required, create_targets can be disabled:

hcl module "eventbridge" { source = "terraform-aws-modules/eventbridge/aws" bus_name = "my-bus" create_targets = false rules = { logs = { description = "Capture log data" event_pattern = jsonencode({ "source" : ["my.app.logs"] }) } } }

With rules and targets together:

hcl module "eventbridge" { source = "terraform-aws-modules/eventbridge/aws" bus_name = "my-bus" rules = { logs = { description = "Capture log data" event_pattern = jsonencode({ "source" : ["my.app.logs"] }) } } targets = { logs = [ { name = "send-logs-to-sqs" arn = aws_sqs_queue.queue.arn }, { name = "send-logs-to-cloudwatch" arn = aws_cloudwatch_log_stream.logs.arn } ] } }

Logging and Delivery Configuration

The module supports EventBridge logging configuration and log delivery to CloudWatch Logs and S3.

An example with full log config and delivery:

hcl module "eventbridge" { source = "terraform-aws-modules/eventbridge/aws" bus_name = "my-bus" log_config = { include_detail = "FULL" level = "INFO" } log_delivery = { cloudwatch_logs = { destination_arn = "arn:aws:logs:us-east-1:123456789012:log-group:my-log-group" } s3 = { destination_arn = "arn:aws:s3:::my-log-bucket" } } rules = { orders = { description = "Capture all order data" event_pattern = jsonencode({ "source" : ["myapp.orders"] }) enabled = true } } targets = { orders = [ { name = "send-orders-to-sqs" arn = aws_sqs_queue.queue.arn dead_letter_arn = aws_sqs_queue.dlq.arn }, { name = "send-orders-to-kinesis" arn = aws_kinesis_stream.this.arn dead_letter_arn = aws_sqs_queue.dlq.arn input_transformer = local.kinesis_input_transformer }, { name = "log-orders-to-cloudwatch" arn = aws_cloudwatch_log_group.this.arn } ] } tags = { Name = "my-bus" } }

Archives and Replays

Support for AWS EventBridge Archives and Replays is provided via create_archives and archives map.

Example:

hcl module "eventbridge_with_archive" { source = "terraform-aws-modules/eventbridge/aws" bus_name = "my-bus" create_archives = true archives = { "my-bus-launch-archive" = { description = "EC2 AutoScaling Event archive", retention_days = 1 event_pattern = <<PATTERN { "source": ["aws.autoscaling"], "detail-type": ["EC2 Instance Launch Successful"] } PATTERN } } tags = { Name = "my-bus" } }

Permissions and Access Control

The module supports IAM policy attachments and various ways to create and attach additional policies.

Example with create_permissions:

hcl module "eventbridge_with_permissions" { source = "terraform-aws-modules/eventbridge/aws" bus_name = "my-bus" create_permissions = true permissions = { "099720109477 DevAccess" = {} "099720109466 ProdAccess" = {} } tags = { Name =

Event Bus, Rules and Scheduler Patterns in Terraform

AWS EventBridge is a serverless event bus that lets your applications, AWS services, and supported SaaS partners publish and react to events in near real-time.

In this guide, you’ll use Terraform and Spacelift to create event buses, define rules with event patterns, build scheduled rules with both awscloudwatchevent_rule and the dedicated EventBridge Scheduler, wire up Lambda, SQS, CloudWatch Logs, and API Destination targets, transform event payloads, and set up retries, dead-letter queues, and archives, with working code at every step.

The core workflow steps are:

  • What is AWS EventBridge?
  • Prerequisites
  • Setting up Terraform for AWS
  • Managing Event Buses with Terraform
  • Configuring EventBridge rules in Terraform
  • Using schedulers with Terraform
  • Event targets in EventBridge using Terraform
  • Monitoring EventBridge with Terraform
  • Best practices for Terraform and EventBridge integration

Prerequisites for Terraform EventBridge work include:

  • AWS CLI configured with appropriate permissions
  • Terraform installed (version 1.0.0 or later)
  • Basic understanding of event-driven architectures
  • Familiarity with JSON/YAML

Project Structure often follows:

terraform-eventbridge/ ├── main.tf ├── variables.tf ├── outputs.tf ├── modules/ │ └── eventbridge/ │ ├── main.tf │ ├── variables.tf │ └── outputs.tf └── patterns/ └── events.json

A manual Event Bus definition without the module looks like:

hcl resource "aws_cloudwatch_event_bus" "main" { name = "${var.project_name}-bus" tags = merge( var.tags, { Name = "${var.project_name}-bus" } ) }

Event Bus Policy example:

hcl resource "aws_cloudwatch_event_bus_policy" "main" { event_bus_name = aws_cloudwatch_event_bus.main.name policy = jsonencode({ Version = "2012-10-17" Statement = [ { Sid = "AllowOtherAccountsPutEvents" Effect = "Allow" Principal = { AWS = var.allowed_account_ids } Action = "events:PutEvents" Resource = aws_cloudwatch_event_bus.main.arn } ] }) }

Schedule Rule:

hcl resource "aws_cloudwatch_event_rule" "schedule" { name = "${var.project_name}-schedule" description = "Schedule-based rule" event_bus_name = aws_cloudwatch_event_bus.main.name schedule_expression = "rate(5 minutes)" tags = merge( var.tags, { Name = "${var.project_name}-schedule" } ) }

Schedulers and Automated Terraform Operations

AWS EventBridge also provides built-in support for creating schedulers that emit events at scheduled times.

A documented pattern uses the Terraform module to create an AWS CodeBuild project for executing Terraform operations, and Amazon EventBridge Scheduler for triggering AWS CodeBuild project with Terraform operational commands fetched from AWS Systems Manager Parameter Store. This lightweight and abstract module can be re-used by your different use cases as a child module in your Terraform configuration.

Important: This pattern’s workflow is a proof of concept (POC) and we recommend that you only use it in a non-production environment. If you want to use this pattern in a production environment, see Security best practices in IAM in the IAM documentation and make the required changes to all IAM resources.

Solution Overview shows deployment of the AWS Terraform Scheduled Switch module in an AWS account.

  • The Amazon EventBridge Schedule for deletion executes and passes a JSON input with key-value pairs of the commands from AWS Systems Manager Parameter Store for destroying the Amazon MWAA resource to the AWS CodeBuild project that is set as the target.
  • AWS CodeBuild fetches the existing Terraform source code residing in a GitHub repository, which contains the IaC (Infrastructure-as-code) representation of the current Amazon MWAA environment deployed in the account

Feature Comparison Table

Capability Support
Custom Event Bus creation Yes
Rules with event_pattern Yes
Targets for SQS, Kinesis, CloudWatch Logs Yes
Dead Letter Queue configuration Yes
Input Transformer Yes
Logging config include_detail and level Yes
Log delivery to CloudWatch Logs Yes
Log delivery to S3 Yes
Archives and Replays Yes
Permissions and bus policy Yes
Schedules and Schedule Groups Yes
Conditional resource creation Yes

Module Parameters Summary

Common inputs used across examples:

  • source = "terraform-aws-modules/eventbridge/aws"
  • bus_name
  • create_targets
  • create_archives
  • create_permissions
  • rules
  • targets
  • log_config
  • log_delivery
  • tags

The rules block accepts description, event_pattern, and enabled.

The targets block accepts name, arn, deadletterarn, and input_transformer.

Integration Best Practices

When using the terraform-aws-modules/eventbridge/aws module, keep rules focused on a single source pattern per rule name to simplify troubleshooting. Use deadletterarn for SQS and Kinesis targets to avoid silent drops. Enable FULL detail logging for audit buses and route logs to both CloudWatch Logs and S3 for durability. Use create_targets = false during initial rule prototyping to avoid unintended invocations. Tag the bus consistently with Name and project tags for cost allocation.

For scheduled operations, prefer the dedicated EventBridge Scheduler resources over classic event rules where possible, and centralize schedule definitions in a schedule group for easier management.

Conclusion

The terraform-aws-modules/eventbridge/aws module consolidates bus, rules, targets, permissions, connections, destinations, pipes, schedules and schedule groups into a single reusable Terraform interface. It supports the most common use-case which creates custom bus, rules and targets, while also enabling advanced patterns such as logging with includedetail and level, log delivery to CloudWatch Logs and S3, archives with retentiondays and event_pattern, and fine-grained permissions.

Examples in the reference material demonstrate bus-only provisioning, rules without targets, rules with multiple targets including SQS with dead-letter queues, Kinesis with input transformation, and CloudWatch log targets. The module also integrates with EventBridge Scheduler workflows for automated Terraform operations via CodeBuild, illustrating how event-driven scheduling can drive infrastructure lifecycle actions.

For teams building event-driven architectures on AWS, the module reduces boilerplate, enforces consistent tagging and security controls, and provides conditional creation for gradual adoption. Combined with Terraform-managed event buses, rules, and targets, it provides a production-ready foundation for near real-time event processing at scale.

Sources

  1. Market Dev
  2. GitHub
  3. Spacelift Blog
  4. AWS Blog
  5. The Cloud Panda

Related Posts