# Apply this configuration first
provider "aws" {
region = "us-west-2"
}
resource "aws_sns_topic" "sns-topic" {
name = "topicNameOne"
}
resource "aws_sqs_queue" "sqs-queue" {
name = "sqsQueue"
}
resource "aws_sns_topic_subscription" "sns-topic" {
topic_arn = "${aws_sns_topic.sns-topic.arn}"
protocol = "sqs"
endpoint = "${aws_sqs_queue.sqs-queue.arn}"
raw_message_delivery = true
}
# Apply this configuration second
# Note the changed sns-topic resource name
provider "aws" {
region = "us-west-2"
}
resource "aws_sns_topic" "sns-topic" {
name = "topicNameTwo"
}
resource "aws_sqs_queue" "sqs-queue" {
name = "sqsQueue"
}
resource "aws_sns_topic_subscription" "sns-topic" {
topic_arn = "${aws_sns_topic.sns-topic.arn}"
protocol = "sqs"
endpoint = "${aws_sqs_queue.sqs-queue.arn}"
raw_message_delivery = true
}
https://gist.github.com/rkjackson/44739a1fc5be04ef843d31f867dd0971
Please list the steps required to reproduce the issue, for example:
terraform apply first configuration fileterraform apply second configuration fileIn resourceAwsSnsTopicSubscriptionUpdate, there are many changes that can trigger the destruction of the previous topic subscription, and creation of a new one - this destruction also deletes (on the AWS side) any subscription attributes (in this case, RawMessageDelivery) as they are now orphaned.
However, resourceAwsSnsTopicSubscriptionUpdate only creates subscription attributes if d.HasChange is truthy. In the case of a changed topic name (which would result in a change to topic_arn, and thus a resubscription), the new and old state of raw_message_delivery remains true (indicating no change), thus the subscription attribute never gets set for the new subscription.
Hi folks! It turns out I likely "fixed" this in #2967 (switching re-subscriptions from using the update logic to delete/create logic to prevent some Terraform crashes). It was released in v1.7.1 of the AWS provider. Can someone double check if this is still an issue or not on v1.7.1 or higher of the provider please? Thanks!
Confirmed reproduction steps with v1.7.1 resulted in expected behavior.
Thanks so much for confirming! I'll close out this issue, but please let us know if you have any more trouble with this.
I ran into this issue yesterday, using whatever the latest version of the provider was at the time (probably 1.8.0).
I created a new SNS topic to replace another one, so all my SQS queues had to be resubscribed as the ARN updated.
resource "aws_sns_topic_subscription" "sub" {
topic_arn = "${data.terraform_remote_state.sns.sns_arn}"
protocol = "sqs"
endpoint = "${aws_sqs_queue.service.arn}"
raw_message_delivery = true
}
I had to set it to false, apply, set to true then re-apply before the desired config was in place.
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!
Most helpful comment
Hi folks! It turns out I likely "fixed" this in #2967 (switching re-subscriptions from using the update logic to delete/create logic to prevent some Terraform crashes). It was released in v1.7.1 of the AWS provider. Can someone double check if this is still an issue or not on v1.7.1 or higher of the provider please? Thanks!