Terraform v0.11.7
resource "google_storage_bucket" "mybucket" {
name = "mybucket"
location = "europe-west1"
storage_class = "REGIONAL"
force_destroy = true
}
I have a bucket with several objects. The bucket and all objects should be destroyed when using force_destroy=true.
Fail to destroy non-empty bucket with the following error:
- google_storage_bucket.mybucket (destroy): 1 error(s) occurred:
- google_storage_bucket.mybucket: Error trying to delete a bucket containing objects without
force_destroyset to true
After removing all objects manually from the bucket I can destroy it.
Please list the steps required to reproduce the issue, for example:
terraform destroyHey @benbro, I'm not able to reproduce this. Can you post your debug logs as well by setting TF_LOG=DEBUG and putting the output into a gist? (https://www.terraform.io/docs/internals/debugging.html)
I've deleted the GCP project so I can't reproduce it now.
You can close the issue and I'll open it again with debug logs if I'll run into it again.
Thanks
Will do, sorry I couldn't be of more help!
Maybe you didn't do a terraform apply after adding force_destroy = true, at least my best guess.
Hi guys,
I found a way to reproduce this issue:
main.tf and fill it with your bucket's name:resource "google_storage_bucket" "foo" {
name = "YOUR_BUCKET_NAME"
location = "us-east1"
storage_class = "regional"
force_destroy = true
}
terraform import google_storage_bucket.foo YOUR_BUCKET_NAME
terraform destroy -target google_storage_bucket.foo
You will have the error:
google_storage_bucket.foo: Refreshing state... (ID: YOUR_BUCKET_NAME)
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
- google_storage_bucket.foo
Plan: 0 to add, 0 to change, 1 to destroy.
Do you really want to destroy all resources?
Terraform will destroy all your managed infrastructure, as shown above.
There is no undo. Only 'yes' will be accepted to confirm.
Enter a value: yes
google_storage_bucket.foo: Destroying... (ID: YOUR_BUCKET_NAME)
Error: Error applying plan:
1 error(s) occurred:
* google_storage_bucket.foo (destroy): 1 error(s) occurred:
* google_storage_bucket.foo: Error trying to delete a bucket containing objects without `force_destroy` set to true
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
Edit your file terraform.tfstate, and localize your bucket:
"google_storage_bucket.foo": {
"type": "google_storage_bucket",
"depends_on": [],
"primary": {
"id": "YOUR_BUCKET_NAME",
"attributes": {
"cors.#": "0",
"encryption.#": "0",
"force_destroy": "false",
"id": "YOUR_BUCKET_NAME",
Change the line:
"force_destroy": "false",
by:
"force_destroy": "true",
Then you can delete your bucket using terraform destroy.
@danawillow Can we reopen this issue please?
Thanks
Hey @samuel-phan, I'm going to go ahead and mark this as blocked by upstream terraform.
When a resource is imported, the code only has access to the id that it was imported with and not any information that was in the config. This means that at import time, we can't see the force_destroy that you set in your config.
However, there is an easier workaround: like @bradenwright mentioned, running a terraform apply after import should put the force_destroy into state. Give that a try and let me know how it goes!
Hi @danawillow, I tested it and I confirm that running a terraform apply after the import put the force_destroy to true and then, we can destroy the bucket.
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!
Most helpful comment
Maybe you didn't do a
terraform applyafter addingforce_destroy = true, at least my best guess.