hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.29k stars 1.72k forks source link

Add deletion_policy field to google_storage_bucket_object #8617

Open ajlake opened 3 years ago

ajlake commented 3 years ago

Community Note

Description

Introduce a delete_on_destroy field on google_storage_bucket_object. This is the same idea as disable_on_destroy for google_project_service.

This is motivated by a terraform use case I'm dealing whereby a set of template files that change over time are rendered and uploaded to a GCS bucket. Old rendered files need to stay in the bucket until existing infrastructure that references them ages out, but I don't want to track the existence of these old files and templated values in source control. Having this flag would let me solve this nicely.

I'm currently working around this by using null_resource to shell out to gsutil cp ....

The work required to implement this seems straightforward, I'm happy to open a PR if it would be accepted. Thanks.

New or Affected Resource(s)

Potential Terraform Configuration

resource "google_storage_bucket_object" "picture" {
  name              = "butterfly01"
  source            = "/images/nature/garden-tiger-moth.jpg"
  bucket            = "image-store"

  // new field
  delete_on_destroy = false
}

References

b/275717431

upodroid commented 3 years ago

It looks like you are using a bucket that has object versioning enabled.

To force delete an object in a bucket with versioning enabled, you will need to supply the generation number on deletion. We can add a new field called force_destroy that can perma-delete objects like that.

https://cloud.google.com/storage/docs/object-versioning#reference

In the meanwhile, use a bucket that has object versioning disabled.

rileykarson commented 3 years ago

This is a somewhat common request across several resource types, I'll file an upstream issue to see if this can get added at the core level instead of on a resource-by-resource basis. Assigning myself to do so.

melinath commented 1 year ago

@rileykarson does that mean this is an upstream terraform issue?

rileykarson commented 1 year ago

Ehh- I don't think this would go anywhere if filed. This is a request for a deletion_policy field.

melinath commented 1 year ago

See https://googlecloudplatform.github.io/magic-modules/docs/best-practices/ for information on deletion_policy fields.