From d6cbbc3b0f2c28374d8a45d901b584ad28ac8f7e Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Fri, 2 Aug 2024 13:37:31 +0000 Subject: [PATCH] extend data storage_bucket_object with generation (#11335) [upstream:34ef9b7cbd0e070c46c4ea723e46886e6078767d] Signed-off-by: Modular Magician --- .changelog/11335.txt | 3 +++ .../storage/data_source_google_storage_bucket_object.go | 3 +++ .../services/storage/resource_storage_bucket_object.go | 9 +++++++++ website/docs/d/storage_bucket_object.html.markdown | 2 ++ website/docs/r/storage_bucket_object.html.markdown | 2 ++ 5 files changed, 19 insertions(+) create mode 100644 .changelog/11335.txt diff --git a/.changelog/11335.txt b/.changelog/11335.txt new file mode 100644 index 0000000000..552bbb3687 --- /dev/null +++ b/.changelog/11335.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +storage: added `generation` field to `storage_bucket_object` resource +``` \ No newline at end of file diff --git a/google-beta/services/storage/data_source_google_storage_bucket_object.go b/google-beta/services/storage/data_source_google_storage_bucket_object.go index 6b6b7e849b..9aa38daa15 100644 --- a/google-beta/services/storage/data_source_google_storage_bucket_object.go +++ b/google-beta/services/storage/data_source_google_storage_bucket_object.go @@ -91,6 +91,9 @@ func dataSourceGoogleStorageBucketObjectRead(d *schema.ResourceData, meta interf if err := d.Set("metadata", res["metadata"]); err != nil { return fmt.Errorf("Error setting metadata: %s", err) } + if err := d.Set("generation", res["generation"]); err != nil { + return fmt.Errorf("Error setting generation: %s", err) + } d.SetId(bucket + "-" + name) diff --git a/google-beta/services/storage/resource_storage_bucket_object.go b/google-beta/services/storage/resource_storage_bucket_object.go index 97cb845d44..53932c51a0 100644 --- a/google-beta/services/storage/resource_storage_bucket_object.go +++ b/google-beta/services/storage/resource_storage_bucket_object.go @@ -97,6 +97,12 @@ func ResourceStorageBucketObject() *schema.Resource { Description: `Data as string to be uploaded. Must be defined if source is not. Note: The content field is marked as sensitive. To view the raw contents of the object, please define an output.`, }, + "generation": { + Type: schema.TypeInt, + Computed: true, + Description: `The content generation of this object. Used for object versioning and soft delete.`, + }, + "crc32c": { Type: schema.TypeString, Computed: true, @@ -456,6 +462,9 @@ func resourceStorageBucketObjectRead(d *schema.ResourceData, meta interface{}) e if err := d.Set("detect_md5hash", res.Md5Hash); err != nil { return fmt.Errorf("Error setting detect_md5hash: %s", err) } + if err := d.Set("generation", res.Generation); err != nil { + return fmt.Errorf("Error setting generation: %s", err) + } if err := d.Set("crc32c", res.Crc32c); err != nil { return fmt.Errorf("Error setting crc32c: %s", err) } diff --git a/website/docs/d/storage_bucket_object.html.markdown b/website/docs/d/storage_bucket_object.html.markdown index 8272f48c8b..0bb3ae7fe8 100644 --- a/website/docs/d/storage_bucket_object.html.markdown +++ b/website/docs/d/storage_bucket_object.html.markdown @@ -47,6 +47,8 @@ The following attributes are exported: * `content_type` - (Computed) [Content-Type](https://tools.ietf.org/html/rfc7231#section-3.1.1.5) of the object data. Defaults to "application/octet-stream" or "text/plain; charset=utf-8". +* `generation` - (Computed) The content generation of this object. Used for object [versioning](https://cloud.google.com/storage/docs/object-versioning) and [soft delete](https://cloud.google.com/storage/docs/soft-delete). + * `crc32c` - (Computed) Base 64 CRC32 hash of the uploaded data. * `md5hash` - (Computed) Base 64 MD5 hash of the uploaded data. diff --git a/website/docs/r/storage_bucket_object.html.markdown b/website/docs/r/storage_bucket_object.html.markdown index 92eec523d4..c58c1c856f 100644 --- a/website/docs/r/storage_bucket_object.html.markdown +++ b/website/docs/r/storage_bucket_object.html.markdown @@ -104,6 +104,8 @@ One of the following is required: In addition to the arguments listed above, the following computed attributes are exported: +* `generation` - (Computed) The content generation of this object. Used for object [versioning](https://cloud.google.com/storage/docs/object-versioning) and [soft delete](https://cloud.google.com/storage/docs/soft-delete). + * `crc32c` - (Computed) Base 64 CRC32 hash of the uploaded data. * `md5hash` - (Computed) Base 64 MD5 hash of the uploaded data.