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

Fails to refresh state SNS subscription deletions #4888

Closed
tj opened this issue Jan 28, 2016 · 13 comments · Fixed by #4891
Closed

Fails to refresh state SNS subscription deletions #4888

tj opened this issue Jan 28, 2016 · 13 comments · Fixed by #4891

Comments

@tj
Copy link

tj commented Jan 28, 2016

I had some weird issues with SNS topic subscriptions not registering properly unless managed from the UI, so I deleted those at some point and now TF is freaking out. I tried tainting, removing them from config, refreshing state, but the errors won't go away:

* aws_sns_topic_subscription.checker: NotFound: Subscription does not exist
    status code: 404, request id: b8ca0c27-1a62-57b3-8b96-43038a0ead86

Shouldn't terraform just detect that it's gone and create it? I'm not sure if this is a bug or just a UX issue. I swear I've deleted things plenty in the past and have TF bring it back up.

@tj tj changed the title Fails to refresh SNS subscription deletions Fails to refresh state SNS subscription deletions Jan 28, 2016
@stack72
Copy link
Contributor

stack72 commented Jan 28, 2016

@tj thanks for the bug report - I have opened a PR that should fix this now. Basically, when Terraform was not finding the SNS Topic, it wasn't marking it as deleted from it's state.

@radeksimko
Copy link
Member

Reproduced, @stack72 's PR is fixing it.

@tj
Copy link
Author

tj commented Jan 28, 2016

What would you suggest in the meantime before a new release?

@radeksimko
Copy link
Member

@tj You could just taint the resource & disable refresh:

terraform taint aws_sns_topic_subscription.checker
terraform destroy -target=aws_sns_topic_subscription.checker -refresh=false

@tj
Copy link
Author

tj commented Feb 1, 2016

@radeksimko hmm that still gives me the same errors on plan/apply (v0.6.10), so far the only thing that seems to work is to remove my state and start from scratch again

@stack72
Copy link
Contributor

stack72 commented Feb 1, 2016

@tj my fix hasn't been released yet. It will be in 0.6.11

@tj
Copy link
Author

tj commented Feb 1, 2016

@stack72 oh no I was referring to the commands above to taint it and fix the state

@radeksimko
Copy link
Member

I think the problem is that then you'll be getting the error from the delete API method instead of read...
Some APIs allow you to delete deleted resources - i.e. don't error if the resource doesn't exist anymore (not sure if it's right or wrong behaviour). This probably isn't the case.

So unfortunately it's not easily solvable until the bug is fixed, but the release is just coming out, so hopefully you should see it in couple of hours.

@tj
Copy link
Author

tj commented Feb 5, 2016

@radeksimko hmm so I tried with 0.6.11 and still get the same thing:

* aws_sns_topic_subscription.reporter: NotFound: Subscription does not exist
    status code: 404, request id: f28bb78e-928d-53f1-8cf5-f8a078fb803f
* aws_sns_topic_subscription.checker: NotFound: Subscription does not exist
    status code: 404, request id: 50e327be-4a14-54ed-b8ef-6890a0620178

I tried with the tainting as well :(

@tj
Copy link
Author

tj commented Feb 5, 2016

Still can't destroy everything either

@radeksimko
Copy link
Member

@tj It works for me:

provider "aws" {
  region = "us-west-2"
}

resource "aws_sns_topic" "checker" {
  name = "tf-checker-topic"
}

output "arn" {
  value = "${aws_sns_topic.checker.arn}"
}
$ terraform apply
aws_sns_topic.checker: Creating...
  arn:    "" => "<computed>"
  name:   "" => "tf-checker-topic"
  policy: "" => "<computed>"
aws_sns_topic.checker: Creation complete

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path: terraform.tfstate

Outputs:

  arn = arn:aws:sns:us-west-2:111111111111:tf-checker-topic
$ aws --region=us-west-2 sns delete-topic --topic-arn=arn:aws:sns:us-west-2:111111111111:tf-checker-topic
$ terraform plan
Refreshing Terraform state prior to plan...

aws_sns_topic.checker: Refreshing state... (ID: arn:aws:sns:us-west-2:111111111111:tf-checker-topic)

The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

+ aws_sns_topic.checker
    arn:    "" => "<computed>"
    name:   "" => "tf-checker-topic"
    policy: "" => "<computed>"


Plan: 1 to add, 0 to change, 0 to destroy.

It you keep having issues, either with this resource or different one, please open a new issue and attach a repro case & terraform version. If we're able to reproduce it, we should be able to fix it. Thanks!

@jakshi
Copy link

jakshi commented Oct 14, 2016

Have the same issue with aws_cloudfront_distribution resource in terraform 0.7.5
The simplest way to fix that - just remove the resource directly from terraform.tfstate file

@ghost
Copy link

ghost commented Apr 21, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants