Skip to content

Commit

Permalink
s3_bucket_lifecycle_configuration: Fix import, diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed Feb 11, 2022
1 parent 9b116b1 commit 8dfdafb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 3 additions & 4 deletions internal/service/s3/bucket_lifecycle_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/experimental/nullable"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)
Expand Down Expand Up @@ -114,14 +115,12 @@ func ResourceBucketLifecycleConfiguration() *schema.Resource {
},
},
"object_size_greater_than": {
Type: schema.TypeInt,
Type: nullable.TypeNullableInt,
Optional: true,
Default: 0, // API returns 0
},
"object_size_less_than": {
Type: schema.TypeInt,
Type: nullable.TypeNullableInt,
Optional: true,
Default: 0, // API returns 0
},
"prefix": {
Type: schema.TypeString,
Expand Down
14 changes: 11 additions & 3 deletions internal/service/s3/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,15 @@ func FlattenLifecycleRuleExpiration(expiration *s3.LifecycleExpiration) []interf

func FlattenLifecycleRuleFilter(filter *s3.LifecycleRuleFilter) []interface{} {
if filter == nil {
return []interface{}{}
return nil
}

if filter.And == nil &&
filter.ObjectSizeGreaterThan == nil &&
filter.ObjectSizeLessThan == nil &&
(filter.Prefix == nil || aws.StringValue(filter.Prefix) == "") &&
filter.Tag == nil {
return nil
}

m := make(map[string]interface{})
Expand All @@ -897,7 +905,7 @@ func FlattenLifecycleRuleFilter(filter *s3.LifecycleRuleFilter) []interface{} {
m["object_size_less_than"] = int(aws.Int64Value(filter.ObjectSizeLessThan))
}

if filter.Prefix != nil {
if filter.Prefix != nil && aws.StringValue(filter.Prefix) != "" {
m["prefix"] = aws.StringValue(filter.Prefix)
}

Expand Down Expand Up @@ -936,7 +944,7 @@ func FlattenLifecycleRuleFilterAndOperator(andOp *s3.LifecycleRuleAndOperator) [

func FlattenLifecycleRuleFilterTag(tag *s3.Tag) []interface{} {
if tag == nil {
return []interface{}{}
return nil
}

t := KeyValueTags([]*s3.Tag{tag}).IgnoreAWS().Map()
Expand Down

0 comments on commit 8dfdafb

Please sign in to comment.