Skip to content

Commit

Permalink
fix(object): lifecycle rules: fix parsing error when prefix+1tag set (#…
Browse files Browse the repository at this point in the history
…2455)

* fix(object): lifecycle rules: fix parsing error when prefix+1tag set

* whitespace fixing attempt

* whitespace fixing attempt 2

* rework to check for prefix content before setting it

* cassette
  • Loading branch information
Mia-Cross authored Mar 13, 2024
1 parent 4f33d1d commit d2ae788
Show file tree
Hide file tree
Showing 3 changed files with 1,454 additions and 725 deletions.
23 changes: 13 additions & 10 deletions scaleway/resource_object_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,19 +352,22 @@ func resourceBucketLifecycleUpdate(ctx context.Context, conn *s3.S3, d *schema.R

// Filter
tags := expandObjectBucketTags(r["tags"])
ruleHasPrefix := len(r["prefix"].(string)) > 0
filter := &s3.LifecycleRuleFilter{}
if len(tags) == 1 {

if !ruleHasPrefix && len(tags) == 1 {
filter.SetTag(tags[0])
}
if len(tags) > 1 {
lifecycleRuleAndOp := &s3.LifecycleRuleAndOperator{}
if len(r["prefix"].(string)) > 0 {
lifecycleRuleAndOp.SetPrefix(r["prefix"].(string))
} else {
if len(tags) == 0 && ruleHasPrefix {
filter.SetPrefix(r["prefix"].(string))
} else {
lifecycleRuleAndOp := &s3.LifecycleRuleAndOperator{}
lifecycleRuleAndOp.SetTags(tags)
if ruleHasPrefix {
lifecycleRuleAndOp.SetPrefix(r["prefix"].(string))
}
filter.SetAnd(lifecycleRuleAndOp)
}
lifecycleRuleAndOp.SetTags(tags)
filter.SetAnd(lifecycleRuleAndOp)
} else if len(r["prefix"].(string)) > 0 {
filter.SetPrefix(r["prefix"].(string))
}
rule.SetFilter(filter)

Expand Down
30 changes: 29 additions & 1 deletion scaleway/resource_object_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestAccScalewayObjectBucket_Lifecycle(t *testing.T) {
name = "%s"
region = "%s"
acl = "private"
lifecycle_rule {
id = "id1"
prefix = "path1/"
Expand Down Expand Up @@ -348,6 +348,34 @@ func TestAccScalewayObjectBucket_Lifecycle(t *testing.T) {
resource.TestCheckResourceAttr(resourceNameLifecycle, "lifecycle_rule.0.abort_incomplete_multipart_upload_days", "30"),
),
},
{
Config: fmt.Sprintf(`
resource "scaleway_object_bucket" "main-bucket-lifecycle"{
name = "%s"
region = "%s"
acl = "private"
lifecycle_rule {
prefix = "path1/"
enabled = true
tags = {
"deleted" = "true"
}
expiration {
days = 1
}
}
}
`, bucketLifecycle, objectTestsMainRegion),
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayObjectBucketExists(tt, "scaleway_object_bucket.main-bucket-lifecycle", true),
testAccCheckScalewayObjectBucketLifecycleConfigurationExists(tt, resourceNameLifecycle),
resource.TestCheckResourceAttrSet(resourceNameLifecycle, "lifecycle_rule.0.id"),
resource.TestCheckResourceAttr(resourceNameLifecycle, "lifecycle_rule.0.tags.deleted", "true"),
resource.TestCheckResourceAttr(resourceNameLifecycle, "lifecycle_rule.0.prefix", "path1/"),
resource.TestCheckResourceAttr(resourceNameLifecycle, "lifecycle_rule.0.expiration.0.days", "1"),
),
},
},
})
}
Expand Down
Loading

0 comments on commit d2ae788

Please sign in to comment.