diff --git a/mmv1/third_party/terraform/resources/resource_storage_bucket.go.erb b/mmv1/third_party/terraform/resources/resource_storage_bucket.go.erb index 834468063e4d..cb35d33bb754 100644 --- a/mmv1/third_party/terraform/resources/resource_storage_bucket.go.erb +++ b/mmv1/third_party/terraform/resources/resource_storage_bucket.go.erb @@ -208,6 +208,18 @@ func resourceStorageBucket() *schema.Resource { Optional: true, Description: `Relevant only for versioned objects. The number of newer versions of an object to satisfy this condition.`, }, + "matches_prefix": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: `One or more matching name prefixes to satisfy this condition.`, + }, + "matches_suffix": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: `One or more matching name suffixes to satisfy this condition.`, + }, }, }, Description: `The Lifecycle Rule's condition configuration.`, @@ -996,6 +1008,8 @@ func flattenBucketLifecycleRuleCondition(condition *storage.BucketLifecycleRuleC "days_since_custom_time": int(condition.DaysSinceCustomTime), "days_since_noncurrent_time": int(condition.DaysSinceNoncurrentTime), "noncurrent_time_before": condition.NoncurrentTimeBefore, + "matches_prefix": convertStringArrToInterface(condition.MatchesPrefix), + "matches_suffix": convertStringArrToInterface(condition.MatchesSuffix), } if condition.IsLive == nil { ruleCondition["with_state"] = "ANY" @@ -1211,6 +1225,25 @@ func expandStorageBucketLifecycleRuleCondition(v interface{}) (*storage.BucketLi transformed.NoncurrentTimeBefore = v.(string) } + if v, ok := condition["matches_prefix"]; ok { + prefixes := v.([]interface{}) + transformedPrefixes := make([]string, 0, len(prefixes)) + + for _, v := range prefixes { + transformedPrefixes = append(transformedPrefixes, v.(string)) + } + transformed.MatchesPrefix = transformedPrefixes + } + if v, ok := condition["matches_suffix"]; ok { + suffixes := v.([]interface{}) + transformedSuffixes := make([]string, 0, len(suffixes)) + + for _, v := range suffixes { + transformedSuffixes = append(transformedSuffixes, v.(string)) + } + transformed.MatchesSuffix = transformedSuffixes + } + return transformed, nil } @@ -1276,6 +1309,19 @@ func resourceGCSBucketLifecycleRuleConditionHash(v interface{}) int { buf.WriteString(fmt.Sprintf("%d-", v.(int))) } + if v, ok := m["matches_prefix"]; ok { + matches_prefixes := v.([]interface{}) + for _, matches_prefix := range matches_prefixes { + buf.WriteString(fmt.Sprintf("%s-", matches_prefix)) + } + } + if v, ok := m["matches_suffix"]; ok { + matches_suffixes := v.([]interface{}) + for _, matches_suffix := range matches_suffixes { + buf.WriteString(fmt.Sprintf("%s-", matches_suffix)) + } + } + return hashcode(buf.String()) } diff --git a/mmv1/third_party/terraform/tests/resource_storage_bucket_test.go.erb b/mmv1/third_party/terraform/tests/resource_storage_bucket_test.go.erb index a2d52dd5dd6d..0c08fb33e0ce 100644 --- a/mmv1/third_party/terraform/tests/resource_storage_bucket_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_storage_bucket_test.go.erb @@ -1381,6 +1381,24 @@ resource "google_storage_bucket" "bucket" { with_state = "ARCHIVED" } } + lifecycle_rule { + action { + type = "Delete" + } + condition { + matches_prefix = ["test"] + age = 2 + } + } + lifecycle_rule { + action { + type = "Delete" + } + condition { + matches_suffix = ["test"] + age = 2 + } + } } `, bucketName) } @@ -1446,6 +1464,24 @@ resource "google_storage_bucket" "bucket" { with_state = "ARCHIVED" } } + lifecycle_rule { + action { + type = "Delete" + } + condition { + matches_prefix = ["test"] + age = 2 + } + } + lifecycle_rule { + action { + type = "Delete" + } + condition { + matches_suffix = ["test"] + age = 2 + } + } } `, bucketName) } diff --git a/mmv1/third_party/terraform/website/docs/r/storage_bucket.html.markdown b/mmv1/third_party/terraform/website/docs/r/storage_bucket.html.markdown index 26c6297b53e9..6cf2e0ecc377 100644 --- a/mmv1/third_party/terraform/website/docs/r/storage_bucket.html.markdown +++ b/mmv1/third_party/terraform/website/docs/r/storage_bucket.html.markdown @@ -125,6 +125,10 @@ The following arguments are supported: * `matches_storage_class` - (Optional) [Storage Class](https://cloud.google.com/storage/docs/storage-classes) of objects to satisfy this condition. Supported values include: `STANDARD`, `MULTI_REGIONAL`, `REGIONAL`, `NEARLINE`, `COLDLINE`, `ARCHIVE`, `DURABLE_REDUCED_AVAILABILITY`. +* `matches_prefix` - (Optional) One or more matching name prefixes to satisfy this condition. + +* `matches_suffix` - (Optional) One or more matching name suffixes to satisfy this condition. + * `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) A date in the RFC 3339 format YYYY-MM-DD. This condition is satisfied when the customTime metadata for the object is set to an earlier date than the date used in this lifecycle condition.