From f4dd6af04c53c9f207ffbe84e82720031c01d4b9 Mon Sep 17 00:00:00 2001 From: upodroid Date: Wed, 11 Nov 2020 18:39:48 +0000 Subject: [PATCH] add more options --- .../resources/resource_storage_bucket.go | 49 +++++++++++++++++-- .../tests/resource_storage_bucket_test.go | 22 ++++++++- .../docs/r/storage_bucket.html.markdown | 8 +++ 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/third_party/terraform/resources/resource_storage_bucket.go b/third_party/terraform/resources/resource_storage_bucket.go index 5f6d5b9be975..37893da79f32 100644 --- a/third_party/terraform/resources/resource_storage_bucket.go +++ b/third_party/terraform/resources/resource_storage_bucket.go @@ -163,6 +163,27 @@ func resourceStorageBucket() *schema.Resource { Optional: true, Description: `Creation date of an object in RFC 3339 (e.g. 2017-06-13) to satisfy this condition.`, }, + "custom_time_before": { + Type: schema.TypeString, + Optional: true, + Description: `Creation date of an object in RFC 3339 (e.g. 2017-06-13) to satisfy this condition.`, + }, + "days_since_custom_time": { + Type: schema.TypeInt, + Optional: true, + Description: `Number of days elapsed since the user-specified timestamp set on an object.`, + }, + "days_since_noncurrent_time": { + Type: schema.TypeInt, + Optional: true, + Description: `Number of days elapsed since the noncurrent timestamp of an object. This + condition is relevant only for versioned objects.`, + }, + "noncurrent_time_before": { + Type: schema.TypeString, + Optional: true, + Description: `Creation date of an object in RFC 3339 (e.g. 2017-06-13) to satisfy this condition.`, + }, "with_state": { Type: schema.TypeString, Computed: true, @@ -1022,10 +1043,14 @@ func flattenBucketLifecycleRuleAction(action *storage.BucketLifecycleRuleAction) func flattenBucketLifecycleRuleCondition(condition *storage.BucketLifecycleRuleCondition) map[string]interface{} { ruleCondition := map[string]interface{}{ - "age": int(condition.Age), - "created_before": condition.CreatedBefore, - "matches_storage_class": convertStringArrToInterface(condition.MatchesStorageClass), - "num_newer_versions": int(condition.NumNewerVersions), + "age": int(condition.Age), + "created_before": condition.CreatedBefore, + "matches_storage_class": convertStringArrToInterface(condition.MatchesStorageClass), + "num_newer_versions": int(condition.NumNewerVersions), + "custom_time_before": condition.CustomTimeBefore, + "days_since_custom_time": int(condition.DaysSinceCustomTime), + "days_since_noncurrent_time": int(condition.DaysSinceNoncurrentTime), + "noncurrent_time_before": condition.NoncurrentTimeBefore, } if condition.IsLive == nil { ruleCondition["with_state"] = "ANY" @@ -1239,6 +1264,22 @@ func expandStorageBucketLifecycleRuleCondition(v interface{}) (*storage.BucketLi transformed.NumNewerVersions = int64(v.(int)) } + if v, ok := condition["custom_time_before"]; ok { + transformed.CustomTimeBefore = v.(string) + } + + if v, ok := condition["days_since_custom_time"]; ok { + transformed.DaysSinceCustomTime = int64(v.(int)) + } + + if v, ok := condition["days_since_noncurrent_time"]; ok { + transformed.DaysSinceNoncurrentTime = int64(v.(int)) + } + + if v, ok := condition["noncurrent_time_before"]; ok { + transformed.NoncurrentTimeBefore = v.(string) + } + return transformed, nil } diff --git a/third_party/terraform/tests/resource_storage_bucket_test.go b/third_party/terraform/tests/resource_storage_bucket_test.go index 1c416b15e2c2..770de01e5899 100644 --- a/third_party/terraform/tests/resource_storage_bucket_test.go +++ b/third_party/terraform/tests/resource_storage_bucket_test.go @@ -1282,13 +1282,22 @@ resource "google_storage_bucket" "bucket" { 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" + created_before = "2019-01-01" + days_since_custom_time = 3 } } lifecycle_rule { @@ -1360,6 +1369,17 @@ resource "google_storage_bucket" "bucket" { condition { age = 10 with_state = "LIVE" + days_since_noncurrent_time = 5 + } + } + lifecycle_rule { + action { + type = "Delete" + } + + condition { + age = 2 + noncurrent_time_before = "2019-01-01" } } } diff --git a/third_party/terraform/website/docs/r/storage_bucket.html.markdown b/third_party/terraform/website/docs/r/storage_bucket.html.markdown index e00d548ca53d..591e88bb0214 100644 --- a/third_party/terraform/website/docs/r/storage_bucket.html.markdown +++ b/third_party/terraform/website/docs/r/storage_bucket.html.markdown @@ -129,6 +129,14 @@ The `condition` block supports the following elements, and requires at least one * `num_newer_versions` - (Optional) Relevant only for versioned objects. The number of newer versions of an object to satisfy this condition. +* `custom_time_before` - (Optional) Creation date of an object in RFC 3339 (e.g. `2017-06-13`) to satisfy this condition. + +* `days_since_custom_time` - (Optional) Date in RFC 3339 (e.g. `2017-06-13`) when an object's Custom-Time metadata is earlier than the date specified in this condition. + +* `days_since_noncurrent_time` - (Optional) Relevant only for versioned objects. Number of days elapsed since the noncurrent timestamp of an object. + +* `noncurrent_time_before` - (Optional) Relevant only for versioned objects. The date in RFC 3339 (e.g. `2017-06-13`) when the object became nonconcurrent. + The `versioning` block supports: * `enabled` - (Required) While set to `true`, versioning is fully enabled for this bucket.