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

Feature Request: Prevent Bucket from getting destroyed #506

Open
Nold360 opened this issue Aug 31, 2023 · 2 comments
Open

Feature Request: Prevent Bucket from getting destroyed #506

Nold360 opened this issue Aug 31, 2023 · 2 comments

Comments

@Nold360
Copy link

Nold360 commented Aug 31, 2023

Description

When creating a bucket & then running terraform destroy the bucket will get deleted.

I would like to prevent the bucket from getting destroyed, even tho everything else (user, policy, ...) are getting destroyed. Sadly this is not possible with terraforms prevent_destroy lifecycle option.

So adding a prevent_destroy option to the bucket resource would be sufficient.

Steps to Reproduce

  1. terraform apply (creates bucket)
  2. terraform destroy (destroyes bucket)

Expected behavior: Bucket gets destoyed

Wanted / Optional behavior: Bucket doesn't get destroyed, but everything else

@felladrin
Copy link
Collaborator

Hi, @Nold360. Thanks for sharing! Can you open a PR with the change you described? That would help a lot, considering maintainers are mostly unavailable these days.
We're also looking for more people to help maintain the provider, in case you're interested!

@tobikris
Copy link
Contributor

I believe that this feature of terraform is already working as expected.

resource "minio_s3_bucket" "test" {
  bucket = "test"

  lifecycle {
    prevent_destroy = true
  }
}

and destroying it again will fail:

$ terraform destroy -target minio_s3_bucket.test
minio_s3_bucket.test3: Refreshing state... [id=test]
╷
│ Warning: Resource targeting is in effect
│ 
│ You are creating a plan with the -target option, which means that the result of this plan may not represent all of the changes requested by the current
│ configuration.
│ 
│ The -target option is not for routine use, and is provided only for exceptional situations such as recovering from errors or mistakes, or when Terraform
│ specifically suggests to use it as part of an error message.
╵
╷
│ Error: Instance cannot be destroyed
│ 
│   on test.tf line 5:
│    5: resource "minio_s3_bucket" "test" {
│ 
│ Resource minio_s3_bucket.test 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.

Is it possible that you are confusing this with commenting out/removing the configuration completely, @Nold360 ?
Because in that case there is no protection by terraform - but that is expected, see https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#prevent_destroy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants