Skip to content

Support for RetryPolicy and DeadLetterConfig in aws_cloudwatch_event_target #27568

Description

@heitorlessa

Current Terraform Version

0.14.5 - Latest as of now

Use-cases

AWS launched support for setting a custom retry configuration on a per Event Target basis, including DLQ.

CloudFormation example: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#aws-resource-events-rule--examples

Attempted Solutions

Using aws_cloudformation_stack resource to make use of additional properties not available in Terraform.

resource "aws_cloudformation_stack" "stack_eventbridge_target_dlq" {
  name          = "stack_eventbridge_target_dlq"
  parameters = {
    DlqQueue = var.event_bridge_target_x_dlq_arn
  }
  template_body = <<STACK
{
  "Parameters" : {
    "DlqQueue" : {
      "Type" : "String",
      "Description" : "SQS DLQ Queue for sending events that couldn't reach their targets"
    }
  },
  "RuleWithRetryAndDLQ": {
      "Type": "AWS::Events::Rule",
      "Properties": {
          "Description": "Test Events Rule",
          "Name": "mynewabc",
          "EventPattern": {
            "source": [
                "aws.ec2"
            ]
          },
          "State": "ENABLED",
          "Targets": [
          {
              "Arn": "arn:aws:sqs:us-west-2:081035103721:demoSQS",
              "Id": "Id1234",
              "RetryPolicy": {
                  "MaximumRetryAttempts": 2,
                  "MaximumEventAgeInSeconds": 400
              },
              "DeadLetterConfig": {
                  "Arn": { "Ref": "DlqQueue" }
              }
          }
          ]
      }
  }
}
STACK
}

Proposal

Here's an example using the same properties names in Terraform syntax:

resource "aws_cloudwatch_event_target" "ecs_scheduled_task" {
  target_id = "run-scheduled-task-every-hour"
  arn       = aws_ecs_cluster.cluster_name.arn
  rule      = aws_cloudwatch_event_rule.every_hour.name
  role_arn  = aws_iam_role.ecs_events.arn

  # HERE
  retry_policy {
      maximum_retry_attempts = 2,
      maximum_age_in_seconds = 400
  }

  dead_letter_config {
      arn = aws_sqs_dlq_queue.arn
  }

References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions