Skip to content

Commit 949e0ec

Browse files
Revert "Add send_age_if_zero field and deprecate no_age. (#11098)" (#11404) (#19052)
[upstream:6d3d295685841b27e94564183f31da739990b73a] Signed-off-by: Modular Magician <[email protected]>
1 parent 3b7b3ad commit 949e0ec

File tree

5 files changed

+30
-64
lines changed

5 files changed

+30
-64
lines changed

.changelog/11404.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:breaking-change
2+
storage: added `send_age_if_zero` field with default value `true` and deprecated `no_age` field. (revert)
3+
```

google/services/storage/resource_storage_bucket.go

+4-24
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ func ResourceStorageBucket() *schema.Resource {
230230
},
231231
"no_age": {
232232
Type: schema.TypeBool,
233-
Deprecated: "`no_age` is deprecated and will be removed in a future major release. Use `send_age_if_zero` instead.",
234233
Optional: true,
235234
Description: `While set true, age value will be omitted.Required to set true when age is unset in the config file.`,
236235
},
@@ -264,12 +263,6 @@ func ResourceStorageBucket() *schema.Resource {
264263
Elem: &schema.Schema{Type: schema.TypeString},
265264
Description: `One or more matching name suffixes to satisfy this condition.`,
266265
},
267-
"send_age_if_zero": {
268-
Type: schema.TypeBool,
269-
Optional: true,
270-
Default: true,
271-
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.`,
272-
},
273266
"send_days_since_noncurrent_time_if_zero": {
274267
Type: schema.TypeBool,
275268
Optional: true,
@@ -1404,21 +1397,13 @@ func flattenBucketLifecycleRuleCondition(index int, d *schema.ResourceData, cond
14041397
ruleCondition["with_state"] = "ARCHIVED"
14051398
}
14061399
}
1407-
// Setting the lifecycle condition virtual fields from the state file if they
1408-
// are already present otherwise setting them to individual default values.
1400+
// setting no_age value from state config since it is terraform only variable and not getting value from backend.
14091401
if v, ok := d.GetOk(fmt.Sprintf("lifecycle_rule.%d.condition", index)); ok {
14101402
state_condition := v.(*schema.Set).List()[0].(map[string]interface{})
14111403
ruleCondition["no_age"] = state_condition["no_age"].(bool)
14121404
ruleCondition["send_days_since_noncurrent_time_if_zero"] = state_condition["send_days_since_noncurrent_time_if_zero"].(bool)
14131405
ruleCondition["send_days_since_custom_time_if_zero"] = state_condition["send_days_since_custom_time_if_zero"].(bool)
14141406
ruleCondition["send_num_newer_versions_if_zero"] = state_condition["send_num_newer_versions_if_zero"].(bool)
1415-
ruleCondition["send_age_if_zero"] = state_condition["send_age_if_zero"].(bool)
1416-
} else {
1417-
ruleCondition["no_age"] = false
1418-
ruleCondition["send_age_if_zero"] = true
1419-
ruleCondition["send_days_since_noncurrent_time_if_zero"] = false
1420-
ruleCondition["send_days_since_custom_time_if_zero"] = false
1421-
ruleCondition["send_num_newer_versions_if_zero"] = false
14221407
}
14231408

14241409
return ruleCondition
@@ -1568,15 +1553,13 @@ func expandStorageBucketLifecycleRuleCondition(v interface{}) (*storage.BucketLi
15681553

15691554
condition := conditions[0].(map[string]interface{})
15701555
transformed := &storage.BucketLifecycleRuleCondition{}
1571-
// Setting high precedence of no_age over age and send_age_if_zero.
1556+
// Setting high precedence of no_age over age when both used together.
15721557
// Only sets age value when no_age is not present or no_age is present and has false value
15731558
if v, ok := condition["no_age"]; !ok || !(v.(bool)) {
15741559
if v, ok := condition["age"]; ok {
15751560
age := int64(v.(int))
1576-
u, ok := condition["send_age_if_zero"]
1577-
if age > 0 || (ok && u.(bool)) {
1578-
transformed.Age = &age
1579-
}
1561+
transformed.Age = &age
1562+
transformed.ForceSendFields = append(transformed.ForceSendFields, "Age")
15801563
}
15811564
}
15821565

@@ -1690,9 +1673,6 @@ func resourceGCSBucketLifecycleRuleConditionHash(v interface{}) int {
16901673
if v, ok := m["no_age"]; ok && v.(bool) {
16911674
buf.WriteString(fmt.Sprintf("%t-", v.(bool)))
16921675
} else {
1693-
if v, ok := m["send_age_if_zero"]; ok {
1694-
buf.WriteString(fmt.Sprintf("%t-", v.(bool)))
1695-
}
16961676
if v, ok := m["age"]; ok {
16971677
buf.WriteString(fmt.Sprintf("%d-", v.(int)))
16981678
}

google/services/storage/resource_storage_bucket_test.go

+19-24
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ func TestAccStorageBucket_lifecycleRulesMultiple(t *testing.T) {
462462
ResourceName: "google_storage_bucket.bucket",
463463
ImportState: true,
464464
ImportStateVerify: true,
465-
ImportStateVerifyIgnore: []string{"force_destroy", "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", "lifecycle_rule.3.condition.0.send_age_if_zero", "lifecycle_rule.4.condition.0.send_age_if_zero", "lifecycle_rule.5.condition.0.send_age_if_zero", "lifecycle_rule.6.condition.0.send_age_if_zero", "lifecycle_rule.7.condition.0.send_age_if_zero", "lifecycle_rule.8.condition.0.send_age_if_zero", "lifecycle_rule.9.condition.0.send_age_if_zero"},
465+
ImportStateVerifyIgnore: []string{"force_destroy"},
466466
},
467467
{
468468
Config: testAccStorageBucket_lifecycleRulesMultiple_update(bucketName),
@@ -471,7 +471,7 @@ func TestAccStorageBucket_lifecycleRulesMultiple(t *testing.T) {
471471
ResourceName: "google_storage_bucket.bucket",
472472
ImportState: true,
473473
ImportStateVerify: true,
474-
ImportStateVerifyIgnore: []string{"force_destroy", "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", "lifecycle_rule.3.condition.0.send_age_if_zero", "lifecycle_rule.4.condition.0.send_age_if_zero", "lifecycle_rule.5.condition.0.send_age_if_zero", "lifecycle_rule.6.condition.0.send_age_if_zero", "lifecycle_rule.7.condition.0.send_age_if_zero", "lifecycle_rule.8.condition.0.send_age_if_zero", "lifecycle_rule.9.condition.0.send_age_if_zero"},
474+
ImportStateVerifyIgnore: []string{"force_destroy"},
475475
},
476476
},
477477
})
@@ -500,7 +500,7 @@ func TestAccStorageBucket_lifecycleRuleStateLive(t *testing.T) {
500500
ResourceName: "google_storage_bucket.bucket",
501501
ImportState: true,
502502
ImportStateVerify: true,
503-
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero", "lifecycle_rule.1.condition.0.send_age_if_zero"},
503+
ImportStateVerifyIgnore: []string{"force_destroy"},
504504
},
505505
},
506506
})
@@ -529,7 +529,7 @@ func TestAccStorageBucket_lifecycleRuleStateArchived(t *testing.T) {
529529
ResourceName: "google_storage_bucket.bucket",
530530
ImportState: true,
531531
ImportStateVerify: true,
532-
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
532+
ImportStateVerifyIgnore: []string{"force_destroy"},
533533
},
534534
{
535535
Config: testAccStorageBucket_lifecycleRule_withStateArchived(bucketName),
@@ -543,7 +543,7 @@ func TestAccStorageBucket_lifecycleRuleStateArchived(t *testing.T) {
543543
ResourceName: "google_storage_bucket.bucket",
544544
ImportState: true,
545545
ImportStateVerify: true,
546-
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
546+
ImportStateVerifyIgnore: []string{"force_destroy"},
547547
},
548548
},
549549
})
@@ -572,7 +572,7 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
572572
ResourceName: "google_storage_bucket.bucket",
573573
ImportState: true,
574574
ImportStateVerify: true,
575-
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
575+
ImportStateVerifyIgnore: []string{"force_destroy"},
576576
},
577577
{
578578
Config: testAccStorageBucket_lifecycleRule_withStateLive(bucketName),
@@ -586,7 +586,7 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
586586
ResourceName: "google_storage_bucket.bucket",
587587
ImportState: true,
588588
ImportStateVerify: true,
589-
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero", "lifecycle_rule.1.condition.0.send_age_if_zero"},
589+
ImportStateVerifyIgnore: []string{"force_destroy"},
590590
},
591591
{
592592
Config: testAccStorageBucket_lifecycleRule_withStateAny(bucketName),
@@ -600,7 +600,7 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
600600
ResourceName: "google_storage_bucket.bucket",
601601
ImportState: true,
602602
ImportStateVerify: true,
603-
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
603+
ImportStateVerifyIgnore: []string{"force_destroy"},
604604
},
605605
{
606606
Config: testAccStorageBucket_lifecycleRule_withStateArchived(bucketName),
@@ -614,7 +614,7 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
614614
ResourceName: "google_storage_bucket.bucket",
615615
ImportState: true,
616616
ImportStateVerify: true,
617-
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
617+
ImportStateVerifyIgnore: []string{"force_destroy"},
618618
},
619619
},
620620
})
@@ -623,7 +623,6 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
623623
func TestAccStorageBucket_lifecycleRulesVirtualFields(t *testing.T) {
624624
t.Parallel()
625625
var bucket storage.Bucket
626-
zero_age := int64(0)
627626
bucketName := acctest.TestBucketName(t)
628627

629628
acctest.VcrTest(t, resource.TestCase{
@@ -649,30 +648,28 @@ func TestAccStorageBucket_lifecycleRulesVirtualFields(t *testing.T) {
649648
Check: resource.ComposeTestCheckFunc(
650649
testAccCheckStorageBucketExists(
651650
t, "google_storage_bucket.bucket", bucketName, &bucket),
652-
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket, 1),
653-
testAccCheckStorageBucketLifecycleConditionNoAge(&zero_age, &bucket, 2),
651+
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket),
654652
),
655653
},
656654
{
657655
ResourceName: "google_storage_bucket.bucket",
658656
ImportState: true,
659657
ImportStateVerify: true,
660-
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"},
658+
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"},
661659
},
662660
{
663661
Config: testAccStorageBucket_customAttributes_withLifecycleVirtualFieldsUpdate2(bucketName),
664662
Check: resource.ComposeTestCheckFunc(
665663
testAccCheckStorageBucketExists(
666664
t, "google_storage_bucket.bucket", bucketName, &bucket),
667-
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket, 1),
668-
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket, 2),
665+
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket),
669666
),
670667
},
671668
{
672669
ResourceName: "google_storage_bucket.bucket",
673670
ImportState: true,
674671
ImportStateVerify: true,
675-
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"},
672+
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"},
676673
},
677674
{
678675
Config: testAccStorageBucket_customAttributes_withLifecycle1(bucketName),
@@ -851,7 +848,7 @@ func TestAccStorageBucket_update(t *testing.T) {
851848
ResourceName: "google_storage_bucket.bucket",
852849
ImportState: true,
853850
ImportStateVerify: true,
854-
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
851+
ImportStateVerifyIgnore: []string{"force_destroy"},
855852
},
856853
{
857854
Config: testAccStorageBucket_customAttributes_withLifecycle2(bucketName),
@@ -867,7 +864,7 @@ func TestAccStorageBucket_update(t *testing.T) {
867864
ResourceName: "google_storage_bucket.bucket",
868865
ImportState: true,
869866
ImportStateVerify: true,
870-
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero", "lifecycle_rule.1.condition.0.send_age_if_zero"},
867+
ImportStateVerifyIgnore: []string{"force_destroy"},
871868
},
872869
{
873870
Config: testAccStorageBucket_customAttributes_withLifecycle1Update(bucketName),
@@ -883,7 +880,7 @@ func TestAccStorageBucket_update(t *testing.T) {
883880
ResourceName: "google_storage_bucket.bucket",
884881
ImportState: true,
885882
ImportStateVerify: true,
886-
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
883+
ImportStateVerifyIgnore: []string{"force_destroy"},
887884
},
888885
{
889886
Config: testAccStorageBucket_customAttributes(bucketName),
@@ -1685,10 +1682,10 @@ func testAccCheckStorageBucketLifecycleConditionState(expected *bool, b *storage
16851682
}
16861683
}
16871684

1688-
func testAccCheckStorageBucketLifecycleConditionNoAge(expected *int64, b *storage.Bucket, index int) resource.TestCheckFunc {
1685+
func testAccCheckStorageBucketLifecycleConditionNoAge(expected *int64, b *storage.Bucket) resource.TestCheckFunc {
16891686
return func(s *terraform.State) error {
1690-
actual := b.Lifecycle.Rule[index].Condition.Age
1691-
if expected == nil && b.Lifecycle.Rule[index].Condition.Age == nil {
1687+
actual := b.Lifecycle.Rule[1].Condition.Age
1688+
if expected == nil && b.Lifecycle.Rule[1].Condition.Age == nil {
16921689
return nil
16931690
}
16941691
if expected == nil {
@@ -1982,7 +1979,6 @@ resource "google_storage_bucket" "bucket" {
19821979
condition {
19831980
age = 10
19841981
no_age = true
1985-
send_age_if_zero = false
19861982
custom_time_before = "2022-09-01"
19871983
days_since_noncurrent_time = 0
19881984
send_days_since_noncurrent_time_if_zero = false
@@ -1997,7 +1993,6 @@ resource "google_storage_bucket" "bucket" {
19971993
type = "Delete"
19981994
}
19991995
condition {
2000-
send_age_if_zero= false
20011996
custom_time_before = "2022-09-01"
20021997
send_days_since_noncurrent_time_if_zero = false
20031998
send_days_since_custom_time_if_zero = false

website/docs/guides/version_6_upgrade.html.markdown

-10
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,6 @@ resource blocks that contain both fields in a conflicting pair, and remove one o
205205
The fields that are removed from the configuration will still have Computed values,
206206
that are derived from the API.
207207

208-
## Resource: `google_storage_bucket`
209-
210-
### `lifecycle_rule.condition.no_age` is now removed
211-
212-
Previously `lifecycle_rule.condition.age` attirbute was being set zero value by default and `lifecycle_rule.condition.no_age` was introduced to prevent that.
213-
Now `lifecycle_rule.condition.no_age` is no longer supported and `lifecycle_rule.condition.age` won't set a zero value by default.
214-
Removed in favor of the field `lifecycle_rule.condition.send_age_if_zero` which can be used to set zero value for `lifecycle_rule.condition.age` attribute.
215-
216-
For a seamless update, if your state today uses `no_age=true`, update it to remove `no_age` and set `send_age_if_zero=false`. If you do not use `no_age=true`, you will need to add `send_age_if_zero=true` to your state to avoid any changes after updating to 6.0.0.
217-
218208
## Removals
219209

220210
### Resource: `google_identity_platform_project_default_config` is now removed

website/docs/r/storage_bucket.html.markdown

+4-6
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ resource "google_storage_bucket" "auto-expire" {
6969
}
7070
```
7171

72-
## Example Usage - Life cycle settings for storage bucket objects with `send_age_if_zero` disabled
73-
When creating a life cycle condition that does not also include an `age` field, a default `age` of 0 will be set. Set the `send_age_if_zero` flag to `false` to prevent this and avoid any potentially unintended interactions.
72+
## Example Usage - Life cycle settings for storage bucket objects with `no_age` enabled
73+
When creating a life cycle condition that does not also include an `age` field, a default `age` of 0 will be set. Set the `no_age` flag to `true` to prevent this and avoid any potentially unintended interactions.
7474

7575
```hcl
7676
resource "google_storage_bucket" "no-age-enabled" {
@@ -85,7 +85,7 @@ resource "google_storage_bucket" "no-age-enabled" {
8585
}
8686
condition {
8787
days_since_noncurrent_time = 3
88-
send_age_if_zero = false
88+
no_age = true
8989
}
9090
}
9191
}
@@ -173,7 +173,7 @@ The following arguments are supported:
173173

174174
* `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.
175175

176-
* `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.
176+
* `no_age` - (Optional) 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.
177177

178178
* `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.
179179

@@ -193,8 +193,6 @@ The following arguments are supported:
193193

194194
* `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.
195195

196-
* `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.
197-
198196
* `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`.
199197

200198
* `days_since_noncurrent_time` - (Optional) Relevant only for versioned objects. Number of days elapsed since the noncurrent timestamp of an object. 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_noncurrent_time` condition.

0 commit comments

Comments
 (0)