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 v0.9.8
data "aws_subnet" "instance" {
id = "${var.instance_subnet_id}"
}
I should be able to destroy successfully.
If the datasource returns a 404, my destroy fails.
Please list the steps required to reproduce the issue, for example:
terraform applyterraform destroy. This will fail.This still occurs in terraform 0.11.7
Also happens with terraform 0.12
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
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
What's the solution?
terraform destroy -refresh=false will stop the refresh and destroy. See here: https://github.com/ComputeCanada/magic_castle/issues/40#issuecomment-584137330
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!
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.
Most helpful comment
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