Skip to content

Commit

Permalink
Adding support for Autoclass 2.1 (#9272)
Browse files Browse the repository at this point in the history
* Adding support for Autoclass 2.1

* Fixing a typo.

* Fixed tabs

* Adding documentation

* Review fix-ups
  • Loading branch information
thomasmaclean authored Oct 17, 2023
1 parent b9a00e9 commit 09c9e0b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,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 @@ -1142,6 +1148,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 @@ -1169,7 +1178,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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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 @@ -66,8 +68,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 @@ -76,12 +78,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 @@ -90,6 +92,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 @@ -1296,13 +1307,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
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

0 comments on commit 09c9e0b

Please sign in to comment.