From c28c9ef459b493cbc0dba0da73f4deb10c4585b2 Mon Sep 17 00:00:00 2001 From: Matt Morrison Date: Thu, 22 Sep 2016 07:46:35 +1200 Subject: [PATCH] Add support for GCS StorageClass Fixes: #7417 --- .../google/resource_storage_bucket.go | 11 +++++ .../google/resource_storage_bucket_test.go | 48 +++++++++++++++++++ .../google/r/storage_bucket.html.markdown | 4 ++ 3 files changed, 63 insertions(+) diff --git a/builtin/providers/google/resource_storage_bucket.go b/builtin/providers/google/resource_storage_bucket.go index 8da47cab5..6183ee72e 100644 --- a/builtin/providers/google/resource_storage_bucket.go +++ b/builtin/providers/google/resource_storage_bucket.go @@ -56,6 +56,13 @@ func resourceStorageBucket() *schema.Resource { Computed: true, }, + "storage_class": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Default: "STANDARD", + ForceNew: true, + }, + "website": &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -91,6 +98,10 @@ func resourceStorageBucketCreate(d *schema.ResourceData, meta interface{}) error // Create a bucket, setting the acl, location and name. sb := &storage.Bucket{Name: bucket, Location: location} + if v, ok := d.GetOk("storage_class"); ok { + sb.StorageClass = v.(string) + } + if v, ok := d.GetOk("website"); ok { websites := v.([]interface{}) diff --git a/builtin/providers/google/resource_storage_bucket_test.go b/builtin/providers/google/resource_storage_bucket_test.go index de38be841..2e1a9e2be 100644 --- a/builtin/providers/google/resource_storage_bucket_test.go +++ b/builtin/providers/google/resource_storage_bucket_test.go @@ -59,6 +59,45 @@ func TestAccStorageCustomAttributes(t *testing.T) { }) } +func TestAccStorageStorageClass(t *testing.T) { + bucketName := fmt.Sprintf("tf-test-acc-bucket-%d", acctest.RandInt()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccGoogleStorageDestroy, + Steps: []resource.TestStep{ + { + Config: testGoogleStorageBucketsReaderStorageClass(bucketName, "STANDARD"), + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudStorageBucketExists( + "google_storage_bucket.bucket", bucketName), + resource.TestCheckResourceAttr( + "google_storage_bucket.bucket", "storage_class", "STANDARD"), + ), + }, + { + Config: testGoogleStorageBucketsReaderStorageClass(bucketName, "NEARLINE"), + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudStorageBucketExists( + "google_storage_bucket.bucket", bucketName), + resource.TestCheckResourceAttr( + "google_storage_bucket.bucket", "storage_class", "NEARLINE"), + ), + }, + { + Config: testGoogleStorageBucketsReaderStorageClass(bucketName, "DURABLE_REDUCED_AVAILABILITY"), + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudStorageBucketExists( + "google_storage_bucket.bucket", bucketName), + resource.TestCheckResourceAttr( + "google_storage_bucket.bucket", "storage_class", "DURABLE_REDUCED_AVAILABILITY"), + ), + }, + }, + }) +} + func TestAccStorageBucketUpdate(t *testing.T) { bucketName := fmt.Sprintf("tf-test-acl-bucket-%d", acctest.RandInt()) @@ -226,3 +265,12 @@ resource "google_storage_bucket" "bucket" { } `, bucketName) } + +func testGoogleStorageBucketsReaderStorageClass(bucketName string, storageClass string) string { + return fmt.Sprintf(` +resource "google_storage_bucket" "bucket" { + name = "%s" + storage_class = "%s" +} +`, bucketName, storageClass) +} diff --git a/website/source/docs/providers/google/r/storage_bucket.html.markdown b/website/source/docs/providers/google/r/storage_bucket.html.markdown index b32b301d6..9dddc20d3 100644 --- a/website/source/docs/providers/google/r/storage_bucket.html.markdown +++ b/website/source/docs/providers/google/r/storage_bucket.html.markdown @@ -48,6 +48,10 @@ to `google_storage_bucket_acl.predefined_acl`. * `project` - (Optional) The project in which the resource belongs. If it is not provided, the provider project is used. +* `storage_class` - (Optional) The [Storage Class](https://cloud.google.com/storage/docs/storage-classes) of the new bucket. Supported values include: `STANDARD`, `NEARLINE`, `DURABLE_REDUCED_AVAILABILITY` + + > See for more info. + * `website` - (Optional) Configuration if the bucket acts as a website. The optional `website` block supports: