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

Adding support for Autoclass 2.1 #16282

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
3 changes: 3 additions & 0 deletions .changelog/9272.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
storage: added `terminal_storage_class` to the `autoclass` field in `google_storage_bucket` resource
```
12 changes: 11 additions & 1 deletion google/services/storage/resource_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ func ResourceStorageBucket() *schema.Resource {
Required: true,
Description: `While set to true, autoclass automatically transitions objects in your bucket to appropriate storage classes based on each object's access pattern.`,
},
"terminal_storage_class": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `The storage class that objects in the bucket eventually transition to if they are not read for a certain length of time. Supported values include: NEARLINE, ARCHIVE.`,
},
},
},
Description: `The bucket's autoclass configuration.`,
Expand Down Expand Up @@ -1143,6 +1149,9 @@ func expandBucketAutoclass(configured interface{}) *storage.BucketAutoclass {
bucketAutoclass := &storage.BucketAutoclass{}

bucketAutoclass.Enabled = autoclass["enabled"].(bool)
if autoclass["terminal_storage_class"] != "" {
bucketAutoclass.TerminalStorageClass = autoclass["terminal_storage_class"].(string)
}
bucketAutoclass.ForceSendFields = append(bucketAutoclass.ForceSendFields, "Enabled")

return bucketAutoclass
Expand Down Expand Up @@ -1170,7 +1179,8 @@ func flattenBucketAutoclass(bucketAutoclass *storage.BucketAutoclass) []map[stri
}

autoclass := map[string]interface{}{
"enabled": bucketAutoclass.Enabled,
"enabled": bucketAutoclass.Enabled,
"terminal_storage_class": bucketAutoclass.TerminalStorageClass,
}
autoclassList = append(autoclassList, autoclass)
return autoclassList
Expand Down
38 changes: 32 additions & 6 deletions google/services/storage/resource_storage_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func TestAccStorageBucket_basic(t *testing.T) {
func TestAccStorageBucket_basicWithAutoclass(t *testing.T) {
t.Parallel()

var bucket storage.Bucket
var updated storage.Bucket
bucketName := acctest.TestBucketName(t)

acctest.VcrTest(t, resource.TestCase{
Expand All @@ -67,8 +69,8 @@ func TestAccStorageBucket_basicWithAutoclass(t *testing.T) {
{
Config: testAccStorageBucket_basicWithAutoclass(bucketName, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"google_storage_bucket.bucket", "force_destroy", "false"),
testAccCheckStorageBucketExists(
t, "google_storage_bucket.bucket", bucketName, &bucket),
),
},
{
Expand All @@ -77,12 +79,12 @@ func TestAccStorageBucket_basicWithAutoclass(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
// Autoclass is ForceNew, so this destroys & recreates, but does test the explicitly disabled config
{
Config: testAccStorageBucket_basicWithAutoclass(bucketName, false),
Config: testAccStorageBucket_basicWithAutoclass_update(bucketName, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"google_storage_bucket.bucket", "force_destroy", "false"),
testAccCheckStorageBucketExists(
t, "google_storage_bucket.bucket", bucketName, &updated),
testAccCheckStorageBucketWasUpdated(&updated, &bucket),
),
},
{
Expand All @@ -91,6 +93,15 @@ func TestAccStorageBucket_basicWithAutoclass(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_basicWithAutoclass(bucketName, false),
},
{
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
},
})
}
Expand Down Expand Up @@ -1297,13 +1308,28 @@ func testAccStorageBucket_basicWithAutoclass(bucketName string, autoclass bool)
resource "google_storage_bucket" "bucket" {
name = "%s"
location = "US"
force_destroy = true
autoclass {
enabled = %t
}
}
`, bucketName, autoclass)
}

func testAccStorageBucket_basicWithAutoclass_update(bucketName string, autoclass bool) string {
return fmt.Sprintf(`
resource "google_storage_bucket" "bucket" {
name = "%s"
location = "US"
force_destroy = true
autoclass {
enabled = %t
terminal_storage_class = "ARCHIVE"
}
}
`, bucketName, autoclass)
}

func testAccStorageBucket_requesterPays(bucketName string, pays bool) string {
return fmt.Sprintf(`
resource "google_storage_bucket" "bucket" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/storage_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ The following arguments are supported:

* `enabled` - (Required) While set to `true`, autoclass automatically transitions objects in your bucket to appropriate storage classes based on each object's access pattern.

* `terminal_storage_class` - (Optional) The storage class that objects in the bucket eventually transition to if they are not read for a certain length of time. Supported values include: `NEARLINE`, `ARCHIVE`.

<a name="nested_versioning"></a>The `versioning` block supports:

* `enabled` - (Required) While set to `true`, versioning is fully enabled for this bucket.
Expand Down