From d206144d57132103b19dbc9ec2b34336f55defd7 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 8 Aug 2024 13:13:45 -0700 Subject: [PATCH] Removes `no_age` from `google_storage_bucket` resource. (#11356) (#7923) [upstream:6106c3313c4d4eedd5b3b3c2d5e645ee0dbfd9f7] Signed-off-by: Modular Magician --- .changelog/11356.txt | 3 ++ .../storage/resource_storage_bucket.go | 42 ++++++------------- .../storage/resource_storage_bucket_test.go | 11 ++--- website/docs/r/storage_bucket.html.markdown | 6 +-- 4 files changed, 21 insertions(+), 41 deletions(-) create mode 100644 .changelog/11356.txt diff --git a/.changelog/11356.txt b/.changelog/11356.txt new file mode 100644 index 0000000000..8e02876c06 --- /dev/null +++ b/.changelog/11356.txt @@ -0,0 +1,3 @@ +```release-note:breaking-change +storage: removed `no_age` field from `lifecycle_rule.condition` in the `google_storage_bucket` resource +``` \ No newline at end of file diff --git a/google-beta/services/storage/resource_storage_bucket.go b/google-beta/services/storage/resource_storage_bucket.go index 2f15be1b1d..1b7f163029 100644 --- a/google-beta/services/storage/resource_storage_bucket.go +++ b/google-beta/services/storage/resource_storage_bucket.go @@ -228,12 +228,6 @@ func ResourceStorageBucket() *schema.Resource { Optional: true, Description: `Creation date of an object in RFC 3339 (e.g. 2017-06-13) to satisfy this condition.`, }, - "no_age": { - Type: schema.TypeBool, - Deprecated: "`no_age` is deprecated and will be removed in a future major release. Use `send_age_if_zero` instead.", - Optional: true, - Description: `While set true, age value will be omitted.Required to set true when age is unset in the config file.`, - }, "with_state": { Type: schema.TypeString, Computed: true, @@ -267,7 +261,6 @@ func ResourceStorageBucket() *schema.Resource { "send_age_if_zero": { Type: schema.TypeBool, Optional: true, - Default: true, Description: `While set true, age value will be sent in the request even for zero value of the field. This field is only useful for setting 0 value to the age field. It can be used alone or together with age.`, }, "send_days_since_noncurrent_time_if_zero": { @@ -1408,14 +1401,12 @@ func flattenBucketLifecycleRuleCondition(index int, d *schema.ResourceData, cond // are already present otherwise setting them to individual default values. if v, ok := d.GetOk(fmt.Sprintf("lifecycle_rule.%d.condition", index)); ok { state_condition := v.(*schema.Set).List()[0].(map[string]interface{}) - ruleCondition["no_age"] = state_condition["no_age"].(bool) ruleCondition["send_days_since_noncurrent_time_if_zero"] = state_condition["send_days_since_noncurrent_time_if_zero"].(bool) ruleCondition["send_days_since_custom_time_if_zero"] = state_condition["send_days_since_custom_time_if_zero"].(bool) ruleCondition["send_num_newer_versions_if_zero"] = state_condition["send_num_newer_versions_if_zero"].(bool) ruleCondition["send_age_if_zero"] = state_condition["send_age_if_zero"].(bool) } else { - ruleCondition["no_age"] = false - ruleCondition["send_age_if_zero"] = true + ruleCondition["send_age_if_zero"] = false ruleCondition["send_days_since_noncurrent_time_if_zero"] = false ruleCondition["send_days_since_custom_time_if_zero"] = false ruleCondition["send_num_newer_versions_if_zero"] = false @@ -1568,15 +1559,10 @@ func expandStorageBucketLifecycleRuleCondition(v interface{}) (*storage.BucketLi condition := conditions[0].(map[string]interface{}) transformed := &storage.BucketLifecycleRuleCondition{} - // Setting high precedence of no_age over age and send_age_if_zero. - // Only sets age value when no_age is not present or no_age is present and has false value - if v, ok := condition["no_age"]; !ok || !(v.(bool)) { - if v, ok := condition["age"]; ok { - age := int64(v.(int)) - u, ok := condition["send_age_if_zero"] - if age > 0 || (ok && u.(bool)) { - transformed.Age = &age - } + if v, ok := condition["age"]; ok { + age := int64(v.(int)) + if u, ok := condition["send_age_if_zero"]; age > 0 || (ok && u.(bool)) { + transformed.Age = &age } } @@ -1687,15 +1673,8 @@ func resourceGCSBucketLifecycleRuleConditionHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) - if v, ok := m["no_age"]; ok && v.(bool) { - buf.WriteString(fmt.Sprintf("%t-", v.(bool))) - } else { - if v, ok := m["send_age_if_zero"]; ok { - buf.WriteString(fmt.Sprintf("%t-", v.(bool))) - } - if v, ok := m["age"]; ok { - buf.WriteString(fmt.Sprintf("%d-", v.(int))) - } + if v, ok := m["age"]; ok { + buf.WriteString(fmt.Sprintf("%d-", v.(int))) } if v, ok := m["days_since_custom_time"]; ok { @@ -1739,6 +1718,10 @@ func resourceGCSBucketLifecycleRuleConditionHash(v interface{}) int { buf.WriteString(fmt.Sprintf("%d-", v.(int))) } + if v, ok := m["send_age_if_zero"]; ok { + buf.WriteString(fmt.Sprintf("%t-", v.(bool))) + } + if v, ok := m["send_days_since_noncurrent_time_if_zero"]; ok { buf.WriteString(fmt.Sprintf("%t-", v.(bool))) } @@ -1861,8 +1844,7 @@ func setStorageBucket(d *schema.ResourceData, config *transport_tpg.Config, res if err := d.Set("autoclass", flattenBucketAutoclass(res.Autoclass)); err != nil { return fmt.Errorf("Error setting autoclass: %s", err) } - // lifecycle_rule contains terraform only variable no_age. - // Passing config("d") to flattener function to set no_age separately. + // Passing config("d") to flattener function to set virtual fields separately. if err := d.Set("lifecycle_rule", flattenBucketLifecycle(d, res.Lifecycle)); err != nil { return fmt.Errorf("Error setting lifecycle_rule: %s", err) } diff --git a/google-beta/services/storage/resource_storage_bucket_test.go b/google-beta/services/storage/resource_storage_bucket_test.go index 21129ae971..dbe78565d1 100644 --- a/google-beta/services/storage/resource_storage_bucket_test.go +++ b/google-beta/services/storage/resource_storage_bucket_test.go @@ -657,14 +657,13 @@ func TestAccStorageBucket_lifecycleRulesVirtualFields(t *testing.T) { ResourceName: "google_storage_bucket.bucket", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.1.condition.0.no_age", "lifecycle_rule.1.condition.0.send_days_since_noncurrent_time_if_zero", "lifecycle_rule.2.condition.0.send_days_since_noncurrent_time_if_zero", "lifecycle_rule.1.condition.0.send_days_since_custom_time_if_zero", "lifecycle_rule.2.condition.0.send_days_since_custom_time_if_zero", "lifecycle_rule.1.condition.0.send_num_newer_versions_if_zero", "lifecycle_rule.2.condition.0.send_num_newer_versions_if_zero", "lifecycle_rule.1.condition.0.send_age_if_zero"}, + ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.1.condition.0.send_days_since_noncurrent_time_if_zero", "lifecycle_rule.2.condition.0.send_days_since_noncurrent_time_if_zero", "lifecycle_rule.1.condition.0.send_days_since_custom_time_if_zero", "lifecycle_rule.2.condition.0.send_days_since_custom_time_if_zero", "lifecycle_rule.1.condition.0.send_num_newer_versions_if_zero", "lifecycle_rule.2.condition.0.send_num_newer_versions_if_zero", "lifecycle_rule.1.condition.0.send_age_if_zero", "lifecycle_rule.2.condition.0.send_age_if_zero"}, }, { Config: testAccStorageBucket_customAttributes_withLifecycleVirtualFieldsUpdate2(bucketName), Check: resource.ComposeTestCheckFunc( testAccCheckStorageBucketExists( t, "google_storage_bucket.bucket", bucketName, &bucket), - testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket, 1), testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket, 2), ), }, @@ -672,7 +671,7 @@ func TestAccStorageBucket_lifecycleRulesVirtualFields(t *testing.T) { ResourceName: "google_storage_bucket.bucket", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.1.condition.0.no_age", "lifecycle_rule.0.condition.0.send_days_since_noncurrent_time_if_zero", "lifecycle_rule.0.condition.0.send_days_since_custom_time_if_zero", "lifecycle_rule.0.condition.0.send_num_newer_versions_if_zero", "lifecycle_rule.0.condition.0.send_age_if_zero", "lifecycle_rule.1.condition.0.send_age_if_zero", "lifecycle_rule.2.condition.0.send_age_if_zero"}, + ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_days_since_noncurrent_time_if_zero", "lifecycle_rule.0.condition.0.send_days_since_custom_time_if_zero", "lifecycle_rule.0.condition.0.send_num_newer_versions_if_zero", "lifecycle_rule.0.condition.0.send_age_if_zero", "lifecycle_rule.1.condition.0.send_age_if_zero", "lifecycle_rule.2.condition.0.send_age_if_zero"}, }, { Config: testAccStorageBucket_customAttributes_withLifecycle1(bucketName), @@ -1870,6 +1869,7 @@ resource "google_storage_bucket" "bucket" { type = "Delete" } condition { + send_age_if_zero = true age = 0 } } @@ -1917,7 +1917,6 @@ resource "google_storage_bucket" "bucket" { } condition { age = 10 - no_age = false days_since_noncurrent_time = 0 send_days_since_noncurrent_time_if_zero = false days_since_custom_time = 0 @@ -1931,7 +1930,6 @@ resource "google_storage_bucket" "bucket" { type = "Delete" } condition { - no_age = true days_since_noncurrent_time = 0 send_days_since_noncurrent_time_if_zero = true days_since_custom_time = 0 @@ -1945,6 +1943,7 @@ resource "google_storage_bucket" "bucket" { type = "Delete" } condition { + send_age_if_zero = true send_days_since_noncurrent_time_if_zero = true send_days_since_custom_time_if_zero = true send_num_newer_versions_if_zero = true @@ -1966,7 +1965,6 @@ resource "google_storage_bucket" "bucket" { } condition { age = 10 - no_age = false days_since_noncurrent_time = 0 send_days_since_noncurrent_time_if_zero = true days_since_custom_time = 0 @@ -1981,7 +1979,6 @@ resource "google_storage_bucket" "bucket" { } condition { age = 10 - no_age = true send_age_if_zero = false custom_time_before = "2022-09-01" days_since_noncurrent_time = 0 diff --git a/website/docs/r/storage_bucket.html.markdown b/website/docs/r/storage_bucket.html.markdown index 8304aba71f..db1b5e7e8a 100644 --- a/website/docs/r/storage_bucket.html.markdown +++ b/website/docs/r/storage_bucket.html.markdown @@ -171,9 +171,7 @@ The following arguments are supported: The `condition` block supports the following elements, and requires at least one to be defined. If you specify multiple conditions in a rule, an object has to match all of the conditions for the action to be taken: -* `age` - (Optional) Minimum age of an object in days to satisfy this condition. If not supplied alongside another condition and without setting `no_age` to `true`, a default `age` of 0 will be set. - -* `no_age` - (Optional, Deprecated) While set `true`, `age` value will be omitted from requests. This prevents a default age of `0` from being applied, and if you do not have an `age` value set, setting this to `true` is strongly recommended. When unset and other conditions are set to zero values, this can result in a rule that applies your action to all files in the bucket. `no_age` is deprecated and will be removed in a future major release. Use `send_age_if_zero` instead. +* `age` - (Optional) Minimum age of an object in days to satisfy this condition. **Note** To set `0` value of `age`, `send_age_if_zero` should be set `true` otherwise `0` value of `age` field will be ignored. * `created_before` - (Optional) A date in the RFC 3339 format YYYY-MM-DD. This condition is satisfied when an object is created before midnight of the specified date in UTC. @@ -193,7 +191,7 @@ The following arguments are supported: * `days_since_custom_time` - (Optional) Days since the date set in the `customTime` metadata for the object. This condition is satisfied when the current date and time is at least the specified number of days after the `customTime`. Due to a current bug you are unable to set this value to `0` within Terraform. When set to `0` it will be ignored, and your state will treat it as though you supplied no `days_since_custom_time` condition. -* `send_age_if_zero` - (Optional, Default: true) While set true, `age` value will be sent in the request even for zero value of the field. This field is only useful and required for setting 0 value to the `age` field. It can be used alone or together with `age` attribute. **NOTE** `age` attibute with `0` value will be ommitted from the API request if `send_age_if_zero` field is having `false` value. +* `send_age_if_zero` - (Optional) While set true, `age` value will be sent in the request even for zero value of the field. This field is only useful and required for setting 0 value to the `age` field. It can be used alone or together with `age` attribute. **NOTE** `age` attibute with `0` value will be ommitted from the API request if `send_age_if_zero` field is having `false` value. * `send_days_since_custom_time_if_zero` - (Optional) While set true, `days_since_custom_time` value will be sent in the request even for zero value of the field. This field is only useful for setting 0 value to the `days_since_custom_time` field. It can be used alone or together with `days_since_custom_time`.