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 #9272

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
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,13 @@ 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),
thomasmaclean marked this conversation as resolved.
Show resolved Hide resolved
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),
thomasmaclean marked this conversation as resolved.
Show resolved Hide resolved
testAccCheckAutoclassTerminalStorageClass("ARCHIVE", &updated),
thomasmaclean marked this conversation as resolved.
Show resolved Hide resolved
),
},
{
Expand Down Expand Up @@ -1244,6 +1247,16 @@ func testAccCheckStorageBucketMissing(t *testing.T, bucketName string) resource.
}
}

func testAccCheckAutoclassTerminalStorageClass(expected string, b *storage.Bucket) resource.TestCheckFunc {
return func(s *terraform.State) error {
actual := b.Autoclass.TerminalStorageClass
if expected != actual {
return fmt.Errorf("expected Autoclass Terminal Storage Class %s, instead got %s", expected, actual)
}
return nil
}
}

func testAccCheckStorageBucketLifecycleConditionState(expected *bool, b *storage.Bucket) resource.TestCheckFunc {
return func(s *terraform.State) error {
actual := b.Lifecycle.Rule[0].Condition.IsLive
Expand Down Expand Up @@ -1296,13 +1309,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