Skip to content

Commit

Permalink
Fixes autoclass permadiff issue (#10716) (#18197)
Browse files Browse the repository at this point in the history
[upstream:098126f39d5bc12cb78a5069a8c68a3079b7e62c]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed May 20, 2024
1 parent b44c535 commit c25b2b2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
13 changes: 13 additions & 0 deletions google/services/storage/resource_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,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 @@ -755,6 +763,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
67 changes: 67 additions & 0 deletions google/services/storage/resource_storage_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,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 c25b2b2

Please sign in to comment.