Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider produced inconsistent result after apply error when changing SNS topic resource name #22275

Closed
NicholasPurdy opened this issue Dec 17, 2021 · 3 comments · Fixed by #22282
Labels
bug Addresses a defect in current functionality. service/sns Issues and PRs that pertain to the sns service. service/sqs Issues and PRs that pertain to the sqs service.
Milestone

Comments

@NicholasPurdy
Copy link

NicholasPurdy commented Dec 17, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

terraform v1.1.1 on linux_amd64
hashicorp/aws v3.70.0

Affected Resource(s)

  • aws_sns_topic

Steps to Reproduce

  1. terraform apply to create the infrastructure
  2. Change the resource name from old_sns_topic to new_sns_topic on lines 12, 17, and 40.
  3. terraform apply again to get the error message

Terraform Configuration Files

terraform {
  backend "s3" {
    region = "us-east-1"
    key = "snsbug-main.tfstate"
  }
}

resource "aws_sqs_queue" "my_test_sqs_queue" {
  name = "my_test_sqs_queue"
}

resource "aws_sns_topic" "old_sns_topic" {
  name = "my_sns_topic"
}

resource "aws_sns_topic_subscription" "sqs_subscription" {
  topic_arn = aws_sns_topic.old_sns_topic.arn
  protocol  = "sqs"
  endpoint  = aws_sqs_queue.my_test_sqs_queue.arn
  raw_message_delivery = true
}

resource "aws_sqs_queue_policy" "sns_queue_policy" {
  queue_url = aws_sqs_queue.my_test_sqs_queue.id
  policy = <<POLICY
{
  "Version": "2012-10-17",
  "Id": "sqspolicy",
  "Statement": [
    {
      "Sid": "First",
      "Effect": "Allow",
      "Principal": {
        "Service": "sns.amazonaws.com"
      },
      "Action": "sqs:SendMessage",
      "Resource": "${aws_sqs_queue.my_test_sqs_queue.arn}",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "${aws_sns_topic.old_sns_topic.arn}"
        }
      }
    }
  ]
}
POLICY
}

Actual Behavior

The "old" SNS topic is destroyed, and terraform fails to create the "new" one.

aws_sns_topic_subscription.sqs_subscription: Destroying... [id=arn:aws:sns:us-east-1:555555555555:my_sns_topic:3f270f07-2497-4feb-b629-eaab47941f9e]
aws_sns_topic_subscription.sqs_subscription: Still destroying... [id=arn:aws:sns:us-east-1:555555555555:my_s...c:3f270f07-2497-4feb-b629-eaab47941f9e, 10s elapsed]
aws_sns_topic_subscription.sqs_subscription: Still destroying... [id=arn:aws:sns:us-east-1:555555555555:my_s...c:3f270f07-2497-4feb-b629-eaab47941f9e, 20s elapsed]
aws_sns_topic_subscription.sqs_subscription: Still destroying... [id=arn:aws:sns:us-east-1:555555555555:my_s...c:3f270f07-2497-4feb-b629-eaab47941f9e, 30s elapsed]
aws_sns_topic_subscription.sqs_subscription: Still destroying... [id=arn:aws:sns:us-east-1:555555555555:my_s...c:3f270f07-2497-4feb-b629-eaab47941f9e, 40s elapsed]
aws_sns_topic_subscription.sqs_subscription: Still destroying... [id=arn:aws:sns:us-east-1:555555555555:my_s...c:3f270f07-2497-4feb-b629-eaab47941f9e, 50s elapsed]
aws_sns_topic_subscription.sqs_subscription: Destruction complete after 58s
aws_sns_topic.old_sns_topic: Destroying... [id=arn:aws:sns:us-east-1:555555555555:my_sns_topic]
aws_sns_topic.new_sns_topic: Creating...
aws_sns_topic.old_sns_topic: Destruction complete after 0s
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to aws_sns_topic.new_sns_topic, provider "provider[\"registry.terraform.io/hashicorp/aws\"]" produced an unexpected new value: Root resource was present, but now absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Expected Behavior

Only the terraform resource name is changing, so in the real world, one should probably manually remove and re-import their resources. But the fact that the apply command fails and leaves your infrastructure in a non-functional state is pretty annoying.

It'd be nice if Terraform could either execute the plan to completion, or detect that the underlying infrastructure has not changed and only the state needs to be updated to account for the new resource name (I'm sure the latter is probably a harder ask).

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. bug Addresses a defect in current functionality. service/sns Issues and PRs that pertain to the sns service. service/sqs Issues and PRs that pertain to the sqs service. labels Dec 17, 2021
@ewbankkit
Copy link
Contributor

aws_sns_topic needs the d.IsNewResource() check added - #16796.

@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Dec 17, 2021
@github-actions github-actions bot added this to the v3.71.0 milestone Dec 21, 2021
@github-actions
Copy link

github-actions bot commented Jan 6, 2022

This functionality has been released in v3.71.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/sns Issues and PRs that pertain to the sns service. service/sqs Issues and PRs that pertain to the sqs service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants