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

Terraform destroy fails if Data Source referred resource is desroyed manually #18385

Closed
rahulpatil18 opened this issue Jul 4, 2018 · 8 comments
Labels

Comments

@rahulpatil18
Copy link

rahulpatil18 commented Jul 4, 2018

Problem Statement-

If the resource(Lets call it foo) is deployed with the help of data source, If the resource(bar) which is referred by data source is already destroyed by manually or by accident, terraform destroy fails while destroying the resource(foo)

Terraform Version - v0.11.6

For example -


data "aws_security_group" "selected" {
id = "SG-ID"
}

output "group_name" {
value = "${aws_security_group.name}"
}


If we try to destory above resource when resource which id (SG-ID) we provided is no more available, Terraform will fail to destroy the resource

Expected Behavior

It should destroy the resources regardless of resources availbility which are refered by data source.

Actual Behavior

It fails to destroy resources

Steps to Reproduce

  1. Use data source resource while creating the resource (Terraform deploy)
  2. Destroy the resource which data source is referring to (manual step)
  3. Try to Destroy the resource (Terraform destroy)
@rahulpatil18 rahulpatil18 changed the title Terraform Destroy fails if Data Source referred resource is desroyed manually Terraform destroy fails if Data Source referred resource is desroyed manually Jul 4, 2018
@rahulpatil18
Copy link
Author

@frezbo

@ghost
Copy link

ghost commented Jul 5, 2018

This issue has been automatically migrated to hashicorp/terraform-provider-aws#5082 because it looks like an issue with that provider. If you believe this is not an issue with the provider, please reply to hashicorp/terraform-provider-aws#5082.

@ghost ghost closed this as completed Jul 5, 2018
@frezbo
Copy link
Contributor

frezbo commented Jul 5, 2018

@tombuildsstuff I don't think this is specific to aws, any other providers data resource should also exhibit this behavior, am I missing context?

@bflad bflad reopened this Jul 5, 2018
@frezbo
Copy link
Contributor

frezbo commented Jul 5, 2018

@bflad thanks, any suggestions or insights into how to solve this, happy to raise PR if its a simple fix

@geekofalltrades
Copy link

In a problem that feels related, if you tweak the configuration of a resource to make it invalid, it will no longer destroy.

For example, I had this piece of configuration:

resource "aws_route53_record" "my_record" {
    zone_id = "[redacted]"
    name = "[redacted]"
    type = "A"

    alias {
        evaluate_target_health = false
        name = "[redacted]"
        zone_id = "[redacted]"
    }
}

I accidentally commented out the zone_id line. Then, when I tried to destroy this resource, I got the following error:

Error: aws_route53_record.my_record: "zone_id": required field is not set

I'm asking Terraform to destroy the resource. Why do I care that my configuration is missing a required field?

It feels like both the missing data source issue (which I have also been suffering) and this issue could be related to Terraform fully validating its config before running a destroy. The validation needed before destroying is much slimmer than that needed before planning and applying.

@hashibot
Copy link
Contributor

Hello! 🤖

This issue seems to be covering the same problem or request as #15386, so we're going to close it just to consolidate the discussion over there. Thanks!

@ayshamdmgit
Copy link

Problem Statement-

If the resource(Lets call it foo) is deployed with the help of data source, If the resource(bar) which is referred by data source is already destroyed by manually or by accident, terraform destroy fails while destroying the resource(foo)

Terraform Version - v0.11.6

For example -

data "aws_security_group" "selected" {
id = "SG-ID"
}

output "group_name" {
value = "${aws_security_group.name}"
}

If we try to destory above resource when resource which id (SG-ID) we provided is no more available, Terraform will fail to destroy the resource

Expected Behavior

It should destroy the resources regardless of resources availbility which are refered by data source.

Actual Behavior

It fails to destroy resources

Steps to Reproduce

  1. Use data source resource while creating the resource (Terraform deploy)
  2. Destroy the resource which data source is referring to (manual step)
  3. Try to Destroy the resource (Terraform destroy)

What was the work around to get the destroy to start working as usual?

@github-actions
Copy link
Contributor

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 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants