Terraform-provider-aws: On plan, redrive_policy is always marked as modified

Created on 18 Jul 2017  路  3Comments  路  Source: hashicorp/terraform-provider-aws

_This issue was originally opened by @kfrn as hashicorp/terraform#15579. It was migrated here as a result of the provider split. The original body of the issue is below._


Every time I run terraform plan, the redrive policies for my SQS queues show up as modified, even though they actually have no changes.

I'm using a module to create my SQS queues.

resource "aws_sqs_queue" "sqs_queue" {
  name                       = "${var.environment}_${var.name}"
  message_retention_seconds  = "${var.sqs_queue["message_retention_seconds"]}"
  visibility_timeout_seconds = "${var.sqs_queue["visibility_timeout_seconds"]}"

  redrive_policy = <<-JSON
    {
      "deadLetterTargetArn": "${aws_sqs_queue.sqs_dead_queue.arn}",
      "maxReceiveCount": "${var.sqs_queue["max_receive_count"]}"
    }
  JSON
}

resource "aws_sqs_queue" "sqs_dead_queue" {
  name                       = "${var.environment}_${var.name}_dead"
  message_retention_seconds  = "${var.sqs_dead_queue["message_retention_seconds"]}"
  visibility_timeout_seconds = "${var.sqs_dead_queue["visibility_timeout_seconds"]}"
}

maxReceiveCount is set in the module variables:

variable "sqs_queue" {
  type = "map"

  default = {
    message_retention_seconds  = 1209600
    visibility_timeout_seconds = 30
    max_receive_count          = 10
  }
}

Terraform Version

Terraform v0.9.8

Expected Behaviour

That no change is detected for the redrive policies, since no change has been made.

Actual Behaviour

screen shot 2017-07-18 at 4 39 38 pm

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform get
  2. terraform plan -var-file=<var-file>.tfvars -out=<my-update>.plan -state=<current-state-file>.tfstate
  3. terraform apply -state-out=<new-state-file>.tfstate <my-update>.plan

References

This problem was discussed in February 2016, here: hashicorp/terraform#5119
It seems to have been because the maxReceiveCount in that person's code was a string, not a number; the bug then garnered a patch (#5888).
So I'm really unsure why this is happening for me. For the record, my maxReceiveCount is definitely an integer.

bug servicsqs

Most helpful comment

@kfrn did you figure out the problem here?

In your configuration above, you have "${var.sqs_queue["max_receive_count"]}". The quotes inside the JSON heredoc are extraneous and not required by Terraform's configuration to pick up the variable interpolation in this case, so your JSON can look like:

redrive_policy = <<-JSON
    {
      "deadLetterTargetArn": "${aws_sqs_queue.sqs_dead_queue.arn}",
      "maxReceiveCount": ${var.sqs_queue["max_receive_count"]}
    }
  JSON

All 3 comments

@kfrn did you figure out the problem here?

In your configuration above, you have "${var.sqs_queue["max_receive_count"]}". The quotes inside the JSON heredoc are extraneous and not required by Terraform's configuration to pick up the variable interpolation in this case, so your JSON can look like:

redrive_policy = <<-JSON
    {
      "deadLetterTargetArn": "${aws_sqs_queue.sqs_dead_queue.arn}",
      "maxReceiveCount": ${var.sqs_queue["max_receive_count"]}
    }
  JSON

Closing due to lack of response and a proposed solution above.

Just a follow-up on this.
I was facing the same issue and removing the extraneous quotes on ${var.sqs_queue["max_receive_count"] fixed the issue

thanks @bflad

Was this page helpful?
0 / 5 - 0 ratings