Dom
Dom

Reputation: 247

Terraform SQS redrive policy vs redrive allow policy

In terraform there seems to be 2 ways to setup a redrive policy (see examples below). Are there any differences between the 2 methods? Is 1 preferred over the other?

Example A

resource "aws_sqs_queue" "Q" {
    name = "example A"
    blah = blah

  redrive_allow_policy = jsonencode({
    redrivePermission = "byQueue",
    sourceQueueArns   = [aws_sqs_queue.otherQ.arn]
  })
}

resource "aws_sqs_queue_redrive_policy" "redrive_policy" {
  queue_url = aws_sqs_queue.otherQ.url

  redrive_policy = jsonencode({
    deadLetterTargetArn = aws_sqs_queue.Q.arn
    maxReceiveCount     = 2
  })
}

Example B

resource "aws_sqs_queue" "Q" {
  name = "example B"
  blah = blah

  redrive_policy = jsonencode({
    deadLetterTargetArn = aws_sqs_queue.otherQ.arn
    maxReceiveCount     = 2
  })
}

resource "aws_sqs_queue_redrive_allow_policy" "redrive_allow_policy" {
  queue_url = aws_sqs_queue.Q.url

  redrive_allow_policy = jsonencode({
    redrivePermission = "byQueue",
    sourceQueueArns   = [aws_sqs_queue.otherQ.arn]
  })
}

note: I may have messed up which queue gets referenced as source in the blocks, don't focus on that this was hastily typed.

Alternatively is it preferred / the same thing to just put both blocks within the initial sqs resource?

resource "aws_sqs_queue" "Q" {
  name = "example B"
  blah = blah

  redrive_policy = jsonencode({
    deadLetterTargetArn = aws_sqs_queue.otherQ.arn
    maxReceiveCount     = 2
  })
  redrive_allow_policy = jsonencode({
    redrivePermission = "byQueue",
    sourceQueueArns   = [aws_sqs_queue.otherQ.arn]
  })
}

Upvotes: 2

Views: 493

Answers (0)

Related Questions