Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

error putting Object Storage lifecycle: MalformedXML: Only one field is accepeted in Filter, either Prefix, Tag or And #2420

Closed
mrcsmlsilva opened this issue Feb 23, 2024 · 0 comments 路 Fixed by #2455
Assignees
Labels
bug object Object storage issues, bugs and feature requests priority:highest Bugs filled by customers, security issues

Comments

@mrcsmlsilva
Copy link

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

1.5.7 with Scaleway provider version 2.37.0

Affected Resource(s)

  • scaleway_object_bucket

Terraform Configuration Files

resource "scaleway_object_bucket" "this" {
  id                  = "fr-par/nexus-cloud-proxies"
  name                = "nexus-cloud-proxies"
  tags                = {}

  lifecycle_rule {
    enabled = true
    id      = "Expire-soft-deleted-objects-in-blobstore-s3-snapshots"
    prefix  = "snapshots/"
    tags    = {
      "deleted" = "true"
    }
    expiration {
      days = 1
    }
  }
}

Debug Output

Panic Output

Expected Behavior

The bucket with the desired lifecycle rule should be created or if the bucket exists (my case) the lifecycle rule should be created.

Actual Behavior

I have the error:
Error: error putting Object Storage lifecycle: MalformedXML: Only one field is accepeted in Filter, either Prefix, Tag or And status code: 400, request id: txg6aff11ceeac94af797db-XXXXXXXXXXXX, host id: txg6aff11ceeac94af797db-XXXXXXXXXXXX

Steps to Reproduce

  1. terraform apply

Important Factoids

I took a look in the code and the issue comes from the code in https://github.com/scaleway/terraform-provider-scaleway/blob/master/scaleway/resource_object_bucket.go#L353 lines 353-368:

		tags := expandObjectBucketTags(r["tags"])
		filter := &s3.LifecycleRuleFilter{}
		if 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))
			}
			lifecycleRuleAndOp.SetTags(tags)
			filter.SetAnd(lifecycleRuleAndOp)
		} else if len(r["prefix"].(string)) > 0 {
			filter.SetPrefix(r["prefix"].(string))
		}
		rule.SetFilter(filter)

In fact, if I add two or more tags in the lifecycle rule there is no error.
Basically, if I have the following lifecycle declaration:

  lifecycle_rule {
    enabled = true
    id      = "Expire-soft-deleted-objects-in-blobstore-s3-snapshots"
    prefix  = "snapshots/"
    tags    = {
      "deleted" = "true"
    }
    expiration {
      days = 1
    }
  }

The second condition in the code above (if len(tags) > 1 ) is not true and the LifecycleRuleAndOperator is not used what causes the issue.

So, we have the following scenarios:
len(tags) >= 0 && len(prefix) == 0 --> Works
len(tags) == 0 && len(prefix) >= 1 --> Works
len(tags) > 1 && len(prefix) >= 1 --> Works
len(tags) == 1 && len(prefix) >= 1 --> Fails

References

This problem is related to the use of the LifecycleRuleAndOperator
Please see, for example: https://stackoverflow.com/questions/69579127/how-can-i-update-a-lifecycle-configuration-with-a-filter-based-on-both-prefix-an

  • #0000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug object Object storage issues, bugs and feature requests priority:highest Bugs filled by customers, security issues
Projects
None yet
3 participants