diff --git a/google/resource_storage_bucket.go b/google/resource_storage_bucket.go index f2331af374f..2e177870973 100644 --- a/google/resource_storage_bucket.go +++ b/google/resource_storage_bucket.go @@ -263,6 +263,12 @@ func resourceStorageBucket() *schema.Resource { }, }, }, + + "default_event_based_hold": { + Type: schema.TypeBool, + Optional: true, + }, + "logging": { Type: schema.TypeList, Optional: true, @@ -354,6 +360,10 @@ func resourceStorageBucketCreate(d *schema.ResourceData, meta interface{}) error } } + if v, ok := d.GetOk("default_event_based_hold"); ok { + sb.DefaultEventBasedHold = v.(bool) + } + if v, ok := d.GetOk("cors"); ok { sb.Cors = expandCors(v.([]interface{})) } @@ -452,6 +462,12 @@ func resourceStorageBucketUpdate(d *schema.ResourceData, meta interface{}) error sb.Cors = expandCors(v.([]interface{})) } + if d.HasChange("default_event_based_hold") { + v := d.Get("default_event_based_hold") + sb.DefaultEventBasedHold = v.(bool) + sb.ForceSendFields = append(sb.ForceSendFields, "DefaultEventBasedHold") + } + if d.HasChange("logging") { if v, ok := d.GetOk("logging"); ok { sb.Logging = expandBucketLogging(v.([]interface{})) @@ -567,6 +583,7 @@ func resourceStorageBucketRead(d *schema.ResourceData, meta interface{}) error { d.Set("encryption", flattenBucketEncryption(res.Encryption)) d.Set("location", res.Location) d.Set("cors", flattenCors(res.Cors)) + d.Set("default_event_based_hold", res.DefaultEventBasedHold) d.Set("logging", flattenBucketLogging(res.Logging)) d.Set("versioning", flattenBucketVersioning(res.Versioning)) d.Set("lifecycle_rule", flattenBucketLifecycle(res.Lifecycle)) diff --git a/google/resource_storage_bucket_test.go b/google/resource_storage_bucket_test.go index e6d8eb1e11d..b3140f2042c 100644 --- a/google/resource_storage_bucket_test.go +++ b/google/resource_storage_bucket_test.go @@ -701,6 +701,28 @@ func TestAccStorageBucket_cors(t *testing.T) { }) } +func TestAccStorageBucket_defaultEventBasedHold(t *testing.T) { + t.Parallel() + + bucketName := fmt.Sprintf("tf-test-acl-bucket-%d", acctest.RandInt()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccStorageBucketDestroy, + Steps: []resource.TestStep{ + { + Config: testAccStorageBucket_defaultEventBasedHold(bucketName), + }, + { + ResourceName: "google_storage_bucket.bucket", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccStorageBucket_encryption(t *testing.T) { t.Parallel() @@ -1171,6 +1193,15 @@ resource "google_storage_bucket" "bucket" { `, bucketName) } +func testAccStorageBucket_defaultEventBasedHold(bucketName string) string { + return fmt.Sprintf(` +resource "google_storage_bucket" "bucket" { + name = "%s" + default_event_based_hold = true +} +`, bucketName) +} + func testAccStorageBucket_forceDestroyWithVersioning(bucketName string) string { return fmt.Sprintf(` resource "google_storage_bucket" "bucket" {