Skip to content

Commit eeac83f

Browse files
Storage autoclass DSF (#8137) (#14902)
* Add DSF for empty object in storage bucket autoclass * Remove extra test step * Write specific DSF for storage autoclass Signed-off-by: Modular Magician <[email protected]>
1 parent ce9e412 commit eeac83f

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

.changelog/8137.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
storage: fixed a bug in `google_storage_bucket` that caused a permadiff when the `autoclass.enabled` field was explicitly set to false
3+
```

google/resource_storage_bucket.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,25 @@ func ResourceStorageBucket() *schema.Resource {
269269
},
270270
},
271271
Description: `The bucket's autoclass configuration.`,
272+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
273+
_, n := d.GetChange(strings.TrimSuffix(k, ".#"))
274+
if !strings.HasSuffix(k, ".#") {
275+
return false
276+
}
277+
var l []interface{}
278+
if new == "1" && old == "0" {
279+
l = n.([]interface{})
280+
contents, ok := l[0].(map[string]interface{})
281+
if !ok {
282+
return false
283+
}
284+
if contents["enabled"] == false {
285+
return true
286+
}
287+
}
288+
return false
289+
},
272290
},
273-
274291
"website": {
275292
Type: schema.TypeList,
276293
Optional: true,

google/resource_storage_bucket_test.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,21 @@ func TestAccStorageBucket_basicWithAutoclass(t *testing.T) {
6767
CheckDestroy: testAccStorageBucketDestroyProducer(t),
6868
Steps: []resource.TestStep{
6969
{
70-
Config: testAccStorageBucket_basicWithAutoclass(bucketName),
70+
Config: testAccStorageBucket_basicWithAutoclass(bucketName, true),
71+
Check: resource.ComposeTestCheckFunc(
72+
resource.TestCheckResourceAttr(
73+
"google_storage_bucket.bucket", "force_destroy", "false"),
74+
),
75+
},
76+
{
77+
ResourceName: "google_storage_bucket.bucket",
78+
ImportState: true,
79+
ImportStateVerify: true,
80+
ImportStateVerifyIgnore: []string{"force_destroy"},
81+
},
82+
// Autoclass is ForceNew, so this destroys & recreates, but does test the explicitly disabled config
83+
{
84+
Config: testAccStorageBucket_basicWithAutoclass(bucketName, false),
7185
Check: resource.ComposeTestCheckFunc(
7286
resource.TestCheckResourceAttr(
7387
"google_storage_bucket.bucket", "force_destroy", "false"),
@@ -1359,16 +1373,16 @@ resource "google_storage_bucket" "bucket" {
13591373
`, bucketName)
13601374
}
13611375

1362-
func testAccStorageBucket_basicWithAutoclass(bucketName string) string {
1376+
func testAccStorageBucket_basicWithAutoclass(bucketName string, autoclass bool) string {
13631377
return fmt.Sprintf(`
13641378
resource "google_storage_bucket" "bucket" {
13651379
name = "%s"
13661380
location = "US"
13671381
autoclass {
1368-
enabled = true
1382+
enabled = %t
13691383
}
13701384
}
1371-
`, bucketName)
1385+
`, bucketName, autoclass)
13721386
}
13731387

13741388
func testAccStorageBucket_requesterPays(bucketName string, pays bool) string {

0 commit comments

Comments
 (0)