error putting Object Storage lifecycle: MalformedXML: Only one field is accepeted in Filter, either Prefix, Tag or And
mrcsmlsilva opened this issue Β· comments
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
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