Skip to content

Commit

Permalink
add defaultEventBasedHold to storage buckets (#1626)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>

Co-authored-by: Martin Nowak <[email protected]>
  • Loading branch information
2 people authored and rileykarson committed Jan 16, 2020
1 parent edf9fe9 commit cfbbb32
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions google-beta/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-beta/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

0 comments on commit cfbbb32

Please sign in to comment.