Skip to content

Commit

Permalink
Revert "Add send_age_if_zero field and deprecate no_age. (#11098)" (#…
Browse files Browse the repository at this point in the history
…11404) (#7926)

[upstream:6d3d295685841b27e94564183f31da739990b73a]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and melinath committed Aug 9, 2024
1 parent e48777f commit d044cab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .changelog/11404.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
storage: added `send_age_if_zero` field with default value `true` and deprecated `no_age` field. (revert)
```
28 changes: 4 additions & 24 deletions google-beta/services/storage/resource_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ func ResourceStorageBucket() *schema.Resource {
},
"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.`,
},
Expand Down Expand Up @@ -264,12 +263,6 @@ func ResourceStorageBucket() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Description: `One or more matching name suffixes to satisfy this condition.`,
},
"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": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -1404,21 +1397,13 @@ func flattenBucketLifecycleRuleCondition(index int, d *schema.ResourceData, cond
ruleCondition["with_state"] = "ARCHIVED"
}
}
// Setting the lifecycle condition virtual fields from the state file if they
// are already present otherwise setting them to individual default values.
// setting no_age value from state config since it is terraform only variable and not getting value from backend.
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_days_since_noncurrent_time_if_zero"] = false
ruleCondition["send_days_since_custom_time_if_zero"] = false
ruleCondition["send_num_newer_versions_if_zero"] = false
}

return ruleCondition
Expand Down Expand Up @@ -1568,15 +1553,13 @@ 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.
// Setting high precedence of no_age over age when both used together.
// 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
}
transformed.Age = &age
transformed.ForceSendFields = append(transformed.ForceSendFields, "Age")
}
}

Expand Down Expand Up @@ -1690,9 +1673,6 @@ func resourceGCSBucketLifecycleRuleConditionHash(v interface{}) int {
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)))
}
Expand Down
43 changes: 19 additions & 24 deletions google-beta/services/storage/resource_storage_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func TestAccStorageBucket_lifecycleRulesMultiple(t *testing.T) {
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
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"},
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_lifecycleRulesMultiple_update(bucketName),
Expand All @@ -471,7 +471,7 @@ func TestAccStorageBucket_lifecycleRulesMultiple(t *testing.T) {
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
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"},
ImportStateVerifyIgnore: []string{"force_destroy"},
},
},
})
Expand Down Expand Up @@ -500,7 +500,7 @@ func TestAccStorageBucket_lifecycleRuleStateLive(t *testing.T) {
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero", "lifecycle_rule.1.condition.0.send_age_if_zero"},
ImportStateVerifyIgnore: []string{"force_destroy"},
},
},
})
Expand Down Expand Up @@ -529,7 +529,7 @@ func TestAccStorageBucket_lifecycleRuleStateArchived(t *testing.T) {
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_lifecycleRule_withStateArchived(bucketName),
Expand All @@ -543,7 +543,7 @@ func TestAccStorageBucket_lifecycleRuleStateArchived(t *testing.T) {
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
ImportStateVerifyIgnore: []string{"force_destroy"},
},
},
})
Expand Down Expand Up @@ -572,7 +572,7 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_lifecycleRule_withStateLive(bucketName),
Expand All @@ -586,7 +586,7 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero", "lifecycle_rule.1.condition.0.send_age_if_zero"},
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_lifecycleRule_withStateAny(bucketName),
Expand All @@ -600,7 +600,7 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_lifecycleRule_withStateArchived(bucketName),
Expand All @@ -614,7 +614,7 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
ImportStateVerifyIgnore: []string{"force_destroy"},
},
},
})
Expand All @@ -623,7 +623,6 @@ func TestAccStorageBucket_lifecycleRuleStateAny(t *testing.T) {
func TestAccStorageBucket_lifecycleRulesVirtualFields(t *testing.T) {
t.Parallel()
var bucket storage.Bucket
zero_age := int64(0)
bucketName := acctest.TestBucketName(t)

acctest.VcrTest(t, resource.TestCase{
Expand All @@ -649,30 +648,28 @@ func TestAccStorageBucket_lifecycleRulesVirtualFields(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckStorageBucketExists(
t, "google_storage_bucket.bucket", bucketName, &bucket),
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket, 1),
testAccCheckStorageBucketLifecycleConditionNoAge(&zero_age, &bucket, 2),
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket),
),
},
{
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.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"},
},
{
Config: testAccStorageBucket_customAttributes_withLifecycleVirtualFieldsUpdate2(bucketName),
Check: resource.ComposeTestCheckFunc(
testAccCheckStorageBucketExists(
t, "google_storage_bucket.bucket", bucketName, &bucket),
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket, 1),
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket, 2),
testAccCheckStorageBucketLifecycleConditionNoAge(nil, &bucket),
),
},
{
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.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"},
},
{
Config: testAccStorageBucket_customAttributes_withLifecycle1(bucketName),
Expand Down Expand Up @@ -851,7 +848,7 @@ func TestAccStorageBucket_update(t *testing.T) {
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_customAttributes_withLifecycle2(bucketName),
Expand All @@ -867,7 +864,7 @@ func TestAccStorageBucket_update(t *testing.T) {
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero", "lifecycle_rule.1.condition.0.send_age_if_zero"},
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_customAttributes_withLifecycle1Update(bucketName),
Expand All @@ -883,7 +880,7 @@ func TestAccStorageBucket_update(t *testing.T) {
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy", "lifecycle_rule.0.condition.0.send_age_if_zero"},
ImportStateVerifyIgnore: []string{"force_destroy"},
},
{
Config: testAccStorageBucket_customAttributes(bucketName),
Expand Down Expand Up @@ -1685,10 +1682,10 @@ func testAccCheckStorageBucketLifecycleConditionState(expected *bool, b *storage
}
}

func testAccCheckStorageBucketLifecycleConditionNoAge(expected *int64, b *storage.Bucket, index int) resource.TestCheckFunc {
func testAccCheckStorageBucketLifecycleConditionNoAge(expected *int64, b *storage.Bucket) resource.TestCheckFunc {
return func(s *terraform.State) error {
actual := b.Lifecycle.Rule[index].Condition.Age
if expected == nil && b.Lifecycle.Rule[index].Condition.Age == nil {
actual := b.Lifecycle.Rule[1].Condition.Age
if expected == nil && b.Lifecycle.Rule[1].Condition.Age == nil {
return nil
}
if expected == nil {
Expand Down Expand Up @@ -1982,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
send_days_since_noncurrent_time_if_zero = false
Expand All @@ -1997,7 +1993,6 @@ resource "google_storage_bucket" "bucket" {
type = "Delete"
}
condition {
send_age_if_zero= false
custom_time_before = "2022-09-01"
send_days_since_noncurrent_time_if_zero = false
send_days_since_custom_time_if_zero = false
Expand Down
10 changes: 0 additions & 10 deletions website/docs/guides/version_6_upgrade.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,6 @@ resource blocks that contain both fields in a conflicting pair, and remove one o
The fields that are removed from the configuration will still have Computed values,
that are derived from the API.

## Resource: `google_storage_bucket`

### `lifecycle_rule.condition.no_age` is now removed

Previously `lifecycle_rule.condition.age` attirbute was being set zero value by default and `lifecycle_rule.condition.no_age` was introduced to prevent that.
Now `lifecycle_rule.condition.no_age` is no longer supported and `lifecycle_rule.condition.age` won't set a zero value by default.
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.

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.

## Removals

### Resource: `google_identity_platform_project_default_config` is now removed
Expand Down
10 changes: 4 additions & 6 deletions website/docs/r/storage_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ resource "google_storage_bucket" "auto-expire" {
}
```

## Example Usage - Life cycle settings for storage bucket objects with `send_age_if_zero` disabled
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.
## Example Usage - Life cycle settings for storage bucket objects with `no_age` enabled
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.

```hcl
resource "google_storage_bucket" "no-age-enabled" {
Expand All @@ -85,7 +85,7 @@ resource "google_storage_bucket" "no-age-enabled" {
}
condition {
days_since_noncurrent_time = 3
send_age_if_zero = false
no_age = true
}
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ The following arguments are supported:

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

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

Expand All @@ -193,8 +193,6 @@ 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_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`.

* `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.
Expand Down

0 comments on commit d044cab

Please sign in to comment.