Skip to content

Commit

Permalink
Fix storage bucket days_since_custom_time update issue (#5558) (#10778)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Dec 20, 2021
1 parent 1ff2d9a commit f99d638
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/5558.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
storage: fixed a bug where `google_storage_bucket.lifecycle_rule.condition.days_since_custom_time` was not updating.
```
4 changes: 4 additions & 0 deletions google/resource_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,10 @@ func resourceGCSBucketLifecycleRuleConditionHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%d-", v.(int)))
}

if v, ok := m["days_since_custom_time"]; ok {
buf.WriteString(fmt.Sprintf("%d-", v.(int)))
}

if v, ok := m["days_since_noncurrent_time"]; ok {
buf.WriteString(fmt.Sprintf("%d-", v.(int)))
}
Expand Down
80 changes: 77 additions & 3 deletions google/resource_storage_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ func TestAccStorageBucket_lifecycleRulesMultiple(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_lifecycleRulesMultiple_update(bucketName),
},
{
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
},
})
}
Expand Down Expand Up @@ -1307,7 +1316,72 @@ resource "google_storage_bucket" "bucket" {
type = "Delete"
}
condition {
matches_storage_class = []
matches_storage_class = []
age = 10
}
}
lifecycle_rule {
action {
type = "Delete"
}
condition {
custom_time_before = "2019-01-01"
}
}
lifecycle_rule {
action {
type = "SetStorageClass"
storage_class = "NEARLINE"
}
condition {
created_before = "2019-01-01"
days_since_custom_time = 3
}
}
lifecycle_rule {
action {
type = "SetStorageClass"
storage_class = "NEARLINE"
}
condition {
num_newer_versions = 10
}
}
lifecycle_rule {
action {
type = "SetStorageClass"
storage_class = "ARCHIVE"
}
condition {
with_state = "ARCHIVED"
}
}
}
`, bucketName)
}

func testAccStorageBucket_lifecycleRulesMultiple_update(bucketName string) string {
return fmt.Sprintf(`
resource "google_storage_bucket" "bucket" {
name = "%s"
location = "US"
force_destroy = true
lifecycle_rule {
action {
type = "SetStorageClass"
storage_class = "NEARLINE"
}
condition {
matches_storage_class = ["COLDLINE"]
age = 2
}
}
lifecycle_rule {
action {
type = "Delete"
}
condition {
matches_storage_class = []
age = 10
}
}
Expand All @@ -1325,8 +1399,8 @@ resource "google_storage_bucket" "bucket" {
storage_class = "NEARLINE"
}
condition {
created_before = "2019-01-01"
days_since_custom_time = 3
created_before = "2019-01-01"
days_since_custom_time = 5
}
}
lifecycle_rule {
Expand Down

0 comments on commit f99d638

Please sign in to comment.