Skip to content

Commit

Permalink
r/s3_bucket: flatten lifecycle rule filter into prefix and/or tags
Browse files Browse the repository at this point in the history
  • Loading branch information
anGie44 committed Feb 4, 2022
1 parent c1d1835 commit 0785495
Showing 1 changed file with 20 additions and 32 deletions.
52 changes: 20 additions & 32 deletions internal/service/s3/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2118,36 +2118,6 @@ func flattenBucketLifecycleRuleExpiration(expiration *s3.LifecycleExpiration) []
return []interface{}{m}
}

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

m := make(map[string]interface{})

if filter.And != nil {
// Prefix
if filter.And.Prefix != nil {
m["prefix"] = aws.StringValue(filter.And.Prefix)
}
// Tag
if len(filter.And.Tags) > 0 {
m["tags"] = KeyValueTags(filter.And.Tags).IgnoreAWS().Map()
}
} else {
// Prefix
if filter.Prefix != nil {
m["prefix"] = aws.StringValue(filter.Prefix)
}
// Tag
if filter.Tag != nil {
m["tags"] = KeyValueTags([]*s3.Tag{filter.Tag}).IgnoreAWS().Map()
}
}

return []interface{}{m}
}

func flattenBucketLifecycleRules(lifecycleRules []*s3.LifecycleRule) []interface{} {
if len(lifecycleRules) == 0 {
return []interface{}{}
Expand Down Expand Up @@ -2175,8 +2145,26 @@ func flattenBucketLifecycleRules(lifecycleRules []*s3.LifecycleRule) []interface
}

// Filter
if lifecycleRule.Filter != nil {
rule["filter"] = flattenBucketLifecycleRuleFilter(lifecycleRule.Filter)
if filter := lifecycleRule.Filter; filter != nil {
if filter.And != nil {
// Prefix
if filter.And.Prefix != nil {
rule["prefix"] = aws.StringValue(filter.And.Prefix)
}
// Tag
if len(filter.And.Tags) > 0 {
rule["tags"] = KeyValueTags(filter.And.Tags).IgnoreAWS().Map()
}
} else {
// Prefix
if filter.Prefix != nil {
rule["prefix"] = aws.StringValue(filter.Prefix)
}
// Tag
if filter.Tag != nil {
rule["tags"] = KeyValueTags([]*s3.Tag{filter.Tag}).IgnoreAWS().Map()
}
}
}

// Prefix
Expand Down

0 comments on commit 0785495

Please sign in to comment.