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

Make resource_google_storage_bucket_object generate diff for md5hash, generation, crc32c if content changes #12541

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package storage

import (
"bytes"
"context"
"fmt"
"io"
"log"
Expand All @@ -24,10 +25,11 @@ import (

func ResourceStorageBucketObject() *schema.Resource {
return &schema.Resource{
Create: resourceStorageBucketObjectCreate,
Read: resourceStorageBucketObjectRead,
Update: resourceStorageBucketObjectUpdate,
Delete: resourceStorageBucketObjectDelete,
Create: resourceStorageBucketObjectCreate,
Read: resourceStorageBucketObjectRead,
Update: resourceStorageBucketObjectUpdate,
Delete: resourceStorageBucketObjectDelete,
CustomizeDiff: resourceStorageBucketObjectCustomizeDiff,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(4 * time.Minute),
Expand Down Expand Up @@ -603,3 +605,35 @@ func flattenObjectRetention(objectRetention *storage.ObjectRetention) []map[stri
retentions = append(retentions, retention)
return retentions
}

func resourceStorageBucketObjectCustomizeDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
localMd5Hash := ""
if source, ok := d.GetOkExists("source"); ok {
localMd5Hash = tpgresource.GetFileMd5Hash(source.(string))
}
if content, ok := d.GetOkExists("content"); ok {
localMd5Hash = tpgresource.GetContentMd5Hash([]byte(content.(string)))
}
if localMd5Hash == "" {
return nil
}

oldMd5Hash, ok := d.GetOkExists("md5hash")
if ok && oldMd5Hash == localMd5Hash {
return nil
}

err := d.SetNewComputed("md5hash")
if err != nil {
return fmt.Errorf("Error re-setting md5hash: %s", err)
}
err = d.SetNewComputed("crc32c")
if err != nil {
return fmt.Errorf("Error re-setting crc32c: %s", err)
}
err = d.SetNewComputed("generation")
if err != nil {
return fmt.Errorf("Error re-setting generation: %s", err)
}
return nil
}
Loading