Skip to content

Commit

Permalink
add defaultEventBasedHold to storage buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak committed Jan 10, 2020
1 parent c5e6b4e commit 381a05c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions products/storage/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ objects:
The list of HTTP headers other than the simple response headers
to give permission for the user-agent to share across domains.
item_type: Api::Type::String
- !ruby/object:Api::Type::Boolean
name: 'defaultEventBasedHold'
description: |
Whether or not to automatically apply an eventBasedHold to new objects
added to the bucket.
- !ruby/object:Api::Type::Array
name: 'defaultObjectAcl'
description: |
Expand Down
17 changes: 17 additions & 0 deletions third_party/terraform/resources/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 third_party/terraform/tests/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
4 changes: 4 additions & 0 deletions third_party/validator/storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func GetStorageBucketApiObject(d TerraformResourceData, config *Config) (map[str
sb.Cors = expandCors(v.([]interface{}))
}

if v, ok := d.GetOk("default_event_based_hold"); ok {
sb.DefaultEventBasedHold = v.(bool)
}

if v, ok := d.GetOk("logging"); ok {
sb.Logging = expandBucketLogging(v.([]interface{}))
}
Expand Down

0 comments on commit 381a05c

Please sign in to comment.