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

Don't refresh datasources during a destroy. #15386

Closed
clstokes opened this issue Jun 23, 2017 · 8 comments
Closed

Don't refresh datasources during a destroy. #15386

clstokes opened this issue Jun 23, 2017 · 8 comments
Labels
bug core v0.9 Issues (primarily bugs) reported against v0.9 releases v0.11 Issues (primarily bugs) reported against v0.11 releases

Comments

@clstokes
Copy link
Contributor

If I reference an external resource in a datasource and later on do a terraform destroy and the datasource lookup fails, then my destroy will fail. If I instruct Terraform to not refresh via -refresh=false, my destroy will complete successfully.

Terraform Version

Terraform v0.9.8

Terraform Configuration Files

data "aws_subnet" "instance" {
  id = "${var.instance_subnet_id}"
}

Expected Behavior

I should be able to destroy successfully.

Actual Behavior

If the datasource returns a 404, my destroy fails.

Steps to Reproduce

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

  1. Create a subnet externally.
  2. terraform apply
  3. Delete the subnet externally.
  4. terraform destroy. This will fail.
@4dz
Copy link

4dz commented Jun 14, 2018

This still occurs in terraform 0.11.7

@hashibot hashibot added v0.11 Issues (primarily bugs) reported against v0.11 releases v0.9 Issues (primarily bugs) reported against v0.9 releases labels Aug 29, 2019
@miguelaferreira
Copy link
Contributor

Also happens with terraform 0.12

@kamranzafar
Copy link

Same thing is happening for ebs snapshot data source, if snapshot is deleted manually before terraform destroy. We are using terraform version 0.12.13

@vincentclee
Copy link

Similar issue with RDS aws_db_snapshot datasource. https://www.terraform.io/docs/providers/aws/d/db_snapshot.html

Code

data "aws_db_snapshot" "latest_prod_snapshot" {
  db_instance_identifier = "${aws_db_instance.prod.id}"
  most_recent            = true
}

# Use the latest production snapshot to create a dev instance.
resource "aws_db_instance" "dev" {
  instance_class      = "db.t3.micro"
  name                = "mydbdev"
  snapshot_identifier = "${data.aws_db_snapshot.latest_prod_snapshot.id}"

  lifecycle {
    ignore_changes = ["snapshot_identifier"]
  }
}

Error

Error: Error refreshing state: 1 error occurred:
 * data.aws_db_snapshot.latest_prod_snapshot: 1 error occurred:
 * data.aws_db_snapshot.latest_prod_snapshot: data.aws_db_snapshot.latest_prod_snapshot: DBSnapshotNotFound: DBSnapshot mydbdev-2019-12-31-08-13 not found.
 status code: 404, request id: 9e3af4f3-5b8f-4dd2-87e6-07c75f40c63d

@ayshamdmgit
Copy link

What's the solution?

@petelopez
Copy link

terraform destroy -refresh=false will stop the refresh and destroy. See here: ComputeCanada/magic_castle#40 (comment)

@jbardin
Copy link
Member

jbardin commented Sep 29, 2020

The separate refresh walk has been removed, and resources are only refreshed as need during plan, so this should no longer be an issue in the upcoming 0.14 release.

Thanks!

@jbardin jbardin closed this as completed Sep 29, 2020
@ghost
Copy link

ghost commented Oct 30, 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 as resolved and limited conversation to collaborators Oct 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug core v0.9 Issues (primarily bugs) reported against v0.9 releases v0.11 Issues (primarily bugs) reported against v0.11 releases
Projects
None yet
Development

No branches or pull requests

10 participants