TerraformPilot

Troubleshooting

Fix Terraform EventBridge Rule - ResourceAlreadyExistsException

Fix AWS EventBridge rule already exists errors in Terraform. Covers rule naming conflicts, event bus configuration, import, and cross-account event patterns.

LLuca Berton1 min read

Quick Answer

#

An EventBridge rule with the same name already exists on the event bus. Import it into Terraform, use environment-prefixed names, or delete the orphaned rule.

The Error

#
Error: creating EventBridge Rule (my-schedule-rule):
  ResourceAlreadyExistsException: Rule my-schedule-rule already exists on EventBus default.

What Causes This Error

#
  1. Rule created manually via Console, CLI, or another IaC tool
  2. Another Terraform workspace manages the same rule name
  3. Failed previous apply — rule was created but not recorded in state
  4. Same rule name on different event bus — rule names are unique per event bus

How to Fix It

#

Solution 1: Import the Existing Rule

#
# Check if the rule exists
aws events describe-rule --name my-schedule-rule
 
# Import — format: event_bus_name/rule_name
terraform import aws_cloudwatch_event_rule.schedule default/my-schedule-rule
 
# For custom event bus
terraform import aws_cloudwatch_event_rule.schedule my-bus/my-schedule-rule

Solution 2: Use Unique Names

#
resource "aws_cloudwatch_event_rule" "schedule" {
  name                = "${var.project}-${var.environment}-daily-cleanup"
  description         = "Trigger daily cleanup Lambda"
  schedule_expression = "cron(0 2 * * ? *)"
  event_bus_name      = "default"
}
 
resource "aws_cloudwatch_event_target" "lambda" {
  rule = aws_cloudwatch_event_rule.schedule.name
  arn  = aws_lambda_function.cleanup.arn
}

Solution 3: Use Custom Event Bus

#

Isolate rules per application with custom event buses:

resource "aws_cloudwatch_event_bus" "app" {
  name = "${var.project}-${var.environment}"
}
 
resource "aws_cloudwatch_event_rule" "process_orders" {
  name           = "process-orders"
  event_bus_name = aws_cloudwatch_event_bus.app.name
 
  event_pattern = jsonencode({
    source      = ["com.myapp.orders"]
    detail-type = ["OrderCreated"]
  })
}

Troubleshooting Checklist

#
  1. ✅ Does the rule exist? (aws events describe-rule --name NAME)
  2. ✅ Which event bus is it on? (default or custom)
  3. ✅ Should you import or delete it?
  4. ✅ Are you using unique names per environment?

Prevention Tips

#
  • Prefix rule names with project and environment
  • Use custom event buses to isolate applications
  • Tag rules with ManagedBy = "terraform"
  • Import existing rules before trying to recreate
#

Conclusion

#

EventBridge rule names must be unique per event bus. Import existing rules, use environment-prefixed names, or isolate applications with custom event buses to prevent naming conflicts.

#Terraform#AWS#Troubleshooting#Error Fix

Share this article