Skip to content

Commit 6d3d295

Browse files
authored
Revert "Add send_age_if_zero field and deprecate no_age. (GoogleCloudPlatform#11098)" (GoogleCloudPlatform#11404)
1 parent 23a41a3 commit 6d3d295

File tree

4 files changed

+27
-64
lines changed

4 files changed

+27
-64
lines changed

mmv1/third_party/terraform/services/storage/resource_storage_bucket.go.erb

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

14231408
return ruleCondition
@@ -1567,15 +1552,13 @@ func expandStorageBucketLifecycleRuleCondition(v interface{}) (*storage.BucketLi
15671552

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

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

mmv1/third_party/terraform/services/storage/resource_storage_bucket_test.go.erb

+19-24
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ func TestAccStorageBucket_lifecycleRulesMultiple(t *testing.T) {
461461
ResourceName: "google_storage_bucket.bucket",
462462
ImportState: true,
463463
ImportStateVerify: true,
464-
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"},
464+
ImportStateVerifyIgnore: []string{"force_destroy"},
465465
},
466466
{
467467
Config: testAccStorageBucket_lifecycleRulesMultiple_update(bucketName),
@@ -470,7 +470,7 @@ func TestAccStorageBucket_lifecycleRulesMultiple(t *testing.T) {
470470
ResourceName: "google_storage_bucket.bucket",
471471
ImportState: true,
472472
ImportStateVerify: true,
473-
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"},
473+
ImportStateVerifyIgnore: []string{"force_destroy"},
474474
},
475475
},
476476
})
@@ -499,7 +499,7 @@ func TestAccStorageBucket_lifecycleRuleStateLive(t *testing.T) {
499499
ResourceName: "google_storage_bucket.bucket",
500500
ImportState: true,
501501
ImportStateVerify: true,
502-
ImportStateVerifyIgnore: []string{"force_destroy","lifecycle_rule.0.condition.0.send_age_if_zero","lifecycle_rule.1.condition.0.send_age_if_zero"},
502+
ImportStateVerifyIgnore: []string{"force_destroy"},
503503
},
504504
},
505505
})
@@ -528,7 +528,7 @@ func TestAccStorageBucket_lifecycleRuleStateArchived(t *testing.T) {
528528
ResourceName: "google_storage_bucket.bucket",
529529
ImportState: true,
530530
ImportStateVerify: true,
531-
ImportStateVerifyIgnore: []string{"force_destroy","lifecycle_rule.0.condition.0.send_age_if_zero"},
531+
ImportStateVerifyIgnore: []string{"force_destroy"},
532532
},
533533
{
534534
Config: testAccStorageBucket_lifecycleRule_withStateArchived(bucketName),
@@ -542,7 +542,7 @@ func TestAccStorageBucket_lifecycleRuleStateArchived(t *testing.T) {
542542
ResourceName: "google_storage_bucket.bucket",
543543
ImportState: true,
544544
ImportStateVerify: true,
545-
ImportStateVerifyIgnore: []string{"force_destroy","lifecycle_rule.0.condition.0.send_age_if_zero"},
545+
ImportStateVerifyIgnore: []string{"force_destroy"},
546546
},
547547
},
548548
})
@@ -571,7 +571,7 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
571571
ResourceName: "google_storage_bucket.bucket",
572572
ImportState: true,
573573
ImportStateVerify: true,
574-
ImportStateVerifyIgnore: []string{"force_destroy","lifecycle_rule.0.condition.0.send_age_if_zero"},
574+
ImportStateVerifyIgnore: []string{"force_destroy"},
575575
},
576576
{
577577
Config: testAccStorageBucket_lifecycleRule_withStateLive(bucketName),
@@ -585,7 +585,7 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
585585
ResourceName: "google_storage_bucket.bucket",
586586
ImportState: true,
587587
ImportStateVerify: true,
588-
ImportStateVerifyIgnore: []string{"force_destroy","lifecycle_rule.0.condition.0.send_age_if_zero","lifecycle_rule.1.condition.0.send_age_if_zero"},
588+
ImportStateVerifyIgnore: []string{"force_destroy"},
589589
},
590590
{
591591
Config: testAccStorageBucket_lifecycleRule_withStateAny(bucketName),
@@ -599,7 +599,7 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
599599
ResourceName: "google_storage_bucket.bucket",
600600
ImportState: true,
601601
ImportStateVerify: true,
602-
ImportStateVerifyIgnore: []string{"force_destroy","lifecycle_rule.0.condition.0.send_age_if_zero"},
602+
ImportStateVerifyIgnore: []string{"force_destroy"},
603603
},
604604
{
605605
Config: testAccStorageBucket_lifecycleRule_withStateArchived(bucketName),
@@ -613,7 +613,7 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
613613
ResourceName: "google_storage_bucket.bucket",
614614
ImportState: true,
615615
ImportStateVerify: true,
616-
ImportStateVerifyIgnore: []string{"force_destroy","lifecycle_rule.0.condition.0.send_age_if_zero"},
616+
ImportStateVerifyIgnore: []string{"force_destroy"},
617617
},
618618
},
619619
})
@@ -622,7 +622,6 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
622622
func TestAccStorageBucket_lifecycleRulesVirtualFields(t *testing.T) {
623623
t.Parallel()
624624
var bucket storage.Bucket
625-
zero_age := int64(0)
626625
bucketName := acctest.TestBucketName(t)
627626

628627
acctest.VcrTest(t, resource.TestCase{
@@ -648,30 +647,28 @@ func TestAccStorageBucket_lifecycleRulesVirtualFields(t *testing.T) {
648647
Check: resource.ComposeTestCheckFunc(
649648
testAccCheckStorageBucketExists(
650649
t, "google_storage_bucket.bucket", bucketName, &bucket),
651-
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket, 1),
652-
testAccCheckStorageBucketLifecycleConditionNoAge(&zero_age, &bucket, 2),
650+
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket),
653651
),
654652
},
655653
{
656654
ResourceName: "google_storage_bucket.bucket",
657655
ImportState: true,
658656
ImportStateVerify: true,
659-
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"},
657+
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"},
660658
},
661659
{
662660
Config: testAccStorageBucket_customAttributes_withLifecycleVirtualFieldsUpdate2(bucketName),
663661
Check: resource.ComposeTestCheckFunc(
664662
testAccCheckStorageBucketExists(
665663
t, "google_storage_bucket.bucket", bucketName, &bucket),
666-
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket, 1),
667-
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket, 2),
664+
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket),
668665
),
669666
},
670667
{
671668
ResourceName: "google_storage_bucket.bucket",
672669
ImportState: true,
673670
ImportStateVerify: true,
674-
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"},
671+
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"},
675672
},
676673
{
677674
Config: testAccStorageBucket_customAttributes_withLifecycle1(bucketName),
@@ -850,7 +847,7 @@ func TestAccStorageBucket_update(t *testing.T) {
850847
ResourceName: "google_storage_bucket.bucket",
851848
ImportState: true,
852849
ImportStateVerify: true,
853-
ImportStateVerifyIgnore: []string{"force_destroy","lifecycle_rule.0.condition.0.send_age_if_zero"},
850+
ImportStateVerifyIgnore: []string{"force_destroy"},
854851
},
855852
{
856853
Config: testAccStorageBucket_customAttributes_withLifecycle2(bucketName),
@@ -866,7 +863,7 @@ func TestAccStorageBucket_update(t *testing.T) {
866863
ResourceName: "google_storage_bucket.bucket",
867864
ImportState: true,
868865
ImportStateVerify: true,
869-
ImportStateVerifyIgnore: []string{"force_destroy","lifecycle_rule.0.condition.0.send_age_if_zero","lifecycle_rule.1.condition.0.send_age_if_zero"},
866+
ImportStateVerifyIgnore: []string{"force_destroy"},
870867
},
871868
{
872869
Config: testAccStorageBucket_customAttributes_withLifecycle1Update(bucketName),
@@ -882,7 +879,7 @@ func TestAccStorageBucket_update(t *testing.T) {
882879
ResourceName: "google_storage_bucket.bucket",
883880
ImportState: true,
884881
ImportStateVerify: true,
885-
ImportStateVerifyIgnore: []string{"force_destroy","lifecycle_rule.0.condition.0.send_age_if_zero"},
882+
ImportStateVerifyIgnore: []string{"force_destroy"},
886883
},
887884
{
888885
Config: testAccStorageBucket_customAttributes(bucketName),
@@ -1684,10 +1681,10 @@ func testAccCheckStorageBucketLifecycleConditionState(expected *bool, b *storage
16841681
}
16851682
}
16861683

1687-
func testAccCheckStorageBucketLifecycleConditionNoAge(expected *int64, b *storage.Bucket, index int) resource.TestCheckFunc {
1684+
func testAccCheckStorageBucketLifecycleConditionNoAge(expected *int64, b *storage.Bucket) resource.TestCheckFunc {
16881685
return func(s *terraform.State) error {
1689-
actual := b.Lifecycle.Rule[index].Condition.Age
1690-
if expected == nil && b.Lifecycle.Rule[index].Condition.Age == nil {
1686+
actual := b.Lifecycle.Rule[1].Condition.Age
1687+
if expected == nil && b.Lifecycle.Rule[1].Condition.Age == nil {
16911688
return nil
16921689
}
16931690
if expected == nil {
@@ -1981,7 +1978,6 @@ resource "google_storage_bucket" "bucket" {
19811978
condition {
19821979
age = 10
19831980
no_age = true
1984-
send_age_if_zero = false
19851981
custom_time_before = "2022-09-01"
19861982
days_since_noncurrent_time = 0
19871983
send_days_since_noncurrent_time_if_zero = false
@@ -1996,7 +1992,6 @@ resource "google_storage_bucket" "bucket" {
19961992
type = "Delete"
19971993
}
19981994
condition {
1999-
send_age_if_zero= false
20001995
custom_time_before = "2022-09-01"
20011996
send_days_since_noncurrent_time_if_zero = false
20021997
send_days_since_custom_time_if_zero = false

mmv1/third_party/terraform/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

mmv1/third_party/terraform/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)