Skip to content

Commit b0562cf

Browse files
committed
Cherrypick storage_bucket lifecycle_rule fix
1 parent e73f468 commit b0562cf

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

.changelog/4192.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
storage: fixed an issue in `google_storage_bucket` where `lifecycle_rules` were always included in update requests
3+
```

google-beta/resource_storage_bucket.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func resourceStorageBucketUpdate(d *schema.ResourceData, meta interface{}) error
476476

477477
sb := &storage.Bucket{}
478478

479-
if d.HasChange("lifecycle_rule") {
479+
if detectLifecycleChange(d) {
480480
lifecycle, err := expandStorageBucketLifecycle(d.Get("lifecycle_rule"))
481481
if err != nil {
482482
return err
@@ -1307,3 +1307,22 @@ func lockRetentionPolicy(bucketsService *storage.BucketsService, bucketName stri
13071307

13081308
return nil
13091309
}
1310+
1311+
// d.HasChange("lifecycle_rule") always returns true, giving false positives. This function detects changes
1312+
// to the list size or the actions/conditions of rules directly.
1313+
func detectLifecycleChange(d *schema.ResourceData) bool {
1314+
if d.HasChange("lifecycle_rule.#") {
1315+
return true
1316+
}
1317+
1318+
if l, ok := d.GetOk("lifecycle_rule"); ok {
1319+
lifecycleRules := l.([]interface{})
1320+
for i := range lifecycleRules {
1321+
if d.HasChange(fmt.Sprintf("lifecycle_rule.%d.action", i)) || d.HasChange(fmt.Sprintf("lifecycle_rule.%d.condition", i)) {
1322+
return true
1323+
}
1324+
}
1325+
}
1326+
1327+
return false
1328+
}

0 commit comments

Comments
 (0)