Skip to content

Conversation

ianmuscat
Copy link

Description

This PR enhances the EventBridge module to support an optional name field within resource definitions (rules, connections, api_destinations, schedule_groups, schedules, and pipes), allowing users to specify custom AWS resource names independently from the Terraform map key identifier. This change is 100% backwards compatible and addresses the use case where users want clean Terraform identifiers while maintaining organizational naming standards for AWS resources.

Motivation and Context

Currently, the module uses the map key as both:

  1. The Terraform resource identifier (e.g., module.eventbridge.aws_cloudwatch_event_rule.this["key"])
  2. The AWS resource name (e.g., key or key-rule if append_rule_postfix = true)

This dual purpose creates challenges when users want:

  • Clean, readable Terraform identifiers (e.g., orders, api, webhook)
  • Descriptive AWS resource names that may differ from the Terraform identifier (e.g., order-processor, external-api, customer-webhook)

Example Use Case

An organization wants:

  • Terraform identifier: module.eventbridge.aws_cloudwatch_event_rule.this["orders"]
  • AWS resource name: order-processor

Currently, they must use the full name as the map key:

rules = {
  "order-processor" = {
    description = "Processes order events"
    schedule_expression = "rate(5 minutes)"
  }
}

This results in less clean Terraform identifiers when using descriptive AWS names.

Solution

This PR allows users to specify a custom name field within resource definitions (while still respecting the append_*_postfix variable settings):

rules = {
  orders = {  # <-- "orders"
    name                = "order-processor"  # <-- "orders-processor"
    description         = "Processes order events"
    schedule_expression = "rate(5 minutes)"
  }
}
terraform plan

[...]

  # module.eventbridge.aws_cloudwatch_event_rule.this["orders"] will be created  # <-- "orders"
  + resource "aws_cloudwatch_event_rule" "this" {
      + arn            = (known after apply)
      + description    = "Capture all order data"
      + event_bus_name = "default"
      + event_pattern  = jsonencode(
            {
              + source = [
                  + "myapp.orders",
                ]
            }
        )
      + force_destroy  = false
      + id             = (known after apply)
      + name           = "order-processor"   # <-- "orders-processor"
      + name_prefix    = (known after apply)
      + region         = "eu-west-1"
      + state          = "DISABLED"
      + tags           = {
          + "Name" = "order-processor"
        }
      + tags_all       = {
          + "Name" = "order-processor"
        }
    }

  # module.eventbridge.aws_cloudwatch_event_target.this["log-orders-to-cloudwatch"] will be created
  + resource "aws_cloudwatch_event_target" "this" {
      + arn            = (known after apply)
      + event_bus_name = "default"
      + force_destroy  = false
      + id             = (known after apply)
      + region         = "eu-west-1"
      + rule           = "order-processor"    # <-- "orders-processor"
      + target_id      = (known after apply)
    }

[...]

This achieves:

  • Terraform identifier: module.eventbridge.aws_cloudwatch_event_rule.this["orders"]
  • AWS resource name: order-processor

Breaking Changes

No breaking changes. This feature is 100% backwards compatible:

  1. Existing configurations work unchanged - If no name field is provided, behavior is identical to the current implementation
  2. Map key remains the Terraform identifier - No changes to resource addressing
  3. append_*_postfix behavior unchanged - Still applies to both map keys and custom names
  4. No breaking changes - All existing functionality preserved

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
    • Updated examples/complete/main.tf to showcase the optional name field feature with the orders rule
  • I have tested and validated these changes using one or more of the provided examples/* projects
    • Tested the examples/complete example to verify custom naming works correctly
    • Verified backwards compatibility by ensuring other rules (emails, crons, ecs) continue to work without the name field
    • Confirmed that Terraform identifiers remain clean (["orders"]) while AWS resource names are descriptive (order-processor)
  • I have executed pre-commit run -a on my pull request
    • Will execute pre-commit checks before final submission

Add optional `name` field support across all EventBridge resource types
(rules, connections, api_destinations, schedule_groups, schedules,
pipes)
allowing users to specify custom AWS resource names independently from
Terraform map key identifiers.

This enhancement enables:
- Clean Terraform identifiers (e.g., `["orders"]`)
- Descriptive AWS resource names (e.g., `order-processor`)
- 100% backwards compatibility with existing configurations
- Respect for `append_*_postfix` variable settings

The feature is opt-in and requires no migration for existing users.
@ianmuscat ianmuscat changed the title Support optional name field in EventBridge resources feat: support optional name field in EventBridge resources Oct 10, 2025
@ianmuscat ianmuscat changed the title feat: support optional name field in EventBridge resources feat: Support optional name field in EventBridge resources Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant