wawawa
wawawa

Reputation: 3375

Terraform destroy error 'Instance cannot be destroyed' and 'Failed getting S3 bucket'

I'm currently trying to destroy a workspace, I know that there are some buckets that have a 'do not destroy' type tag applied to them, so when I run terraform destroy for the first time, I got Instance cannot be destroyed error for two buckets:

Resource module.xxx.aws_s3_bucket.xxx_bucket has
lifecycle.prevent_destroy set, but the plan calls for this resource to be
destroyed. To avoid this error and continue with the plan, either disable
lifecycle.prevent_destroy or reduce the scope of the plan using the -target
flag.

so I navigate to the AWS console and delete them manually then tried to run terraform destroy again, then it's complaining about one of the buckets that I've removed manually: Failed getting S3 bucket: NotFound: Not Found, the other one seems fine.

Does anyone know how to resolve this please? Thanks.

Upvotes: 2

Views: 5824

Answers (1)

Matthew Schuchard
Matthew Schuchard

Reputation: 28864

If you removed the resource with an action external to a modification in the Terraform state (in this situation a bucket removed manually through the console), then you need to update the Terraform state correspondingly. You can do this with the terraform state subcommand. Given your listed example of a resource named module.xxx.aws_s3_bucket.xxx_bucket, it would appear like:

terraform state rm module.xxx.aws_s3_bucket.xxx_bucket

You can find more info in the documentation.

Upvotes: 4

Related Questions