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

add defaultEventBasedHold to storage buckets #5373

Merged
merged 1 commit into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions google/resource_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ func resourceStorageBucket() *schema.Resource {
},
},
},

"default_event_based_hold": {
Type: schema.TypeBool,
Optional: true,
},

"logging": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -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{}))
}
Expand Down Expand Up @@ -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{}))
Expand Down Expand Up @@ -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))
Expand Down
31 changes: 31 additions & 0 deletions google/resource_storage_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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" {
Expand Down