I'm trying to write a config where lambda function is being triggered if there is an instance class change in AWS RDS resource. This is the custom event pattern:
{
  "source": [
    "aws.rds"
  ],
  "detail-type": [
    "RDS DB Instance Event"
  ],
  "detail": {
    "EventID": [
      "RDS-EVENT-0014"
    ]
  }
}
The following is my terraform config for cloud watch event rule resource:
resource "aws_cloudwatch_event_rule" "rds_instance_event" {
  name      = "${var.region}-rds-instance-event"
  description = "This event trigger is for RDS instance events"
  event_pattern = <<EOF
{
  "source": [
    "aws.rds"
  ],
  "detail-type": [
    "RDS DB Instance Event"
  ],
  "detail": {
    "EventID": [
      "RDS-EVENT-0014"
    ]
  }
}
EOF
}
The problem is that event_patter get's uploaded in lexicographical order and the cloud watch event is not being triggered. When I change the event_pattern manually to the original order, it works.
Does anyone know how to fix this?
I tried rendering it from a data template as following, still didn't work.
data "template_file" "event_pattern" {
  template = file("${path.module}/manifests/rds-notification-event-rule.json")
}
resource "aws_cloudwatch_event_rule" "rds_instance_event" {
   name     = "${var.region}-rds-instance-event"
   description = "This event trigger is for RDS instance events"
   event_pattern = data.template_file.event_pattern.rendered
 }