Skip to content

Commit

Permalink
Fixes autoclass permadiff issue (#10716)
Browse files Browse the repository at this point in the history
  • Loading branch information
kautikdk committed May 20, 2024
1 parent 0650b2f commit 098126f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ func ResourceStorageBucket() *schema.Resource {
return true
}
}
if new == "0" && old == "1" {
n := d.Get(strings.TrimSuffix(k, ".#"))
l = n.([]interface{})
contents := l[0].(map[string]interface{})
if contents["enabled"] == false {
return true
}
}
return false
},
},
Expand Down Expand Up @@ -754,6 +762,11 @@ func resourceStorageBucketUpdate(d *schema.ResourceData, meta interface{}) error
if d.HasChange("autoclass") {
if v, ok := d.GetOk("autoclass"); ok {
sb.Autoclass = expandBucketAutoclass(v)
} else {
sb.Autoclass = &storage.BucketAutoclass{
Enabled: false,
ForceSendFields: []string{"Enabled"},
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,73 @@ func TestAccStorageBucket_basicWithAutoclass(t *testing.T) {
})
}

func TestAccStorageBucket_AutoclassDiffSupress(t *testing.T) {
t.Parallel()

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

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccStorageBucketDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccStorageBucket_basic(bucketName),
Check: resource.ComposeTestCheckFunc(
testAccCheckStorageBucketExists(
t, "google_storage_bucket.bucket", bucketName, &bucket),
),
},
{
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_basicWithAutoclass(bucketName,false),
Check: resource.ComposeTestCheckFunc(
testAccCheckStorageBucketExists(
t, "google_storage_bucket.bucket", bucketName, &bucket),
),
},
{
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_basicWithAutoclass(bucketName,true),
Check: resource.ComposeTestCheckFunc(
testAccCheckStorageBucketExists(
t, "google_storage_bucket.bucket", bucketName, &bucket),
),
},
{
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_basic(bucketName),
Check: resource.ComposeTestCheckFunc(
testAccCheckStorageBucketExists(
t, "google_storage_bucket.bucket", bucketName, &bucket),
),
},
{
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
},
})
}

func TestAccStorageBucket_requesterPays(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 098126f

Please sign in to comment.