Search code examples
amazon-web-servicesterraformamazon-cloudwatch-events

terraform plan: error: sqs_target should be a list when trying to create a cloudwatch event target


I am trying to create a aws cloudwatch event target with the following terraform code:


resource "aws_cloudwatch_event_rule" "push-event-processing-sqs" {
   name =         "Push-to-sqs-event-processing-every-2-hours" 
   description =         "Push to SQS event-processing every 2 hours" 
   schedule_expression = "cron(0 /2 ? * * *)"
   is_enabled = "false"
}



resource "aws_cloudwatch_event_target" "target-event-processing-sqs" {
  arn = "arn:aws:sqs:us-west-2:123456789:my-sqs-queue-dev.fifo"
  rule = "${aws_cloudwatch_event_rule.push-event-processing-sqs.name}"
  sqs_target = "foobar"
}

Error I get is:

sqs_target: should be a list

I looked at https://www.terraform.io/docs/providers/aws/r/cloudwatch_event_target.html, but did not get much help.

What kind of list should be it?


Solution

  • So your sqs_target is wrongly used. As per docs it should be of the following format:

    resource "aws_cloudwatch_event_target" "target-event-processing-sqs" {
      ...
      sqs_target {
        message_group_id = "foobar"
      }
    }
    

    message_group_id - (Optional) The FIFO message group ID to use as the target.