Open pvilasra opened 1 month ago
Voting for Prioritization
Volunteering to Work on This Issue
Could you please help me ?
@pvilasra As an alternative, are you able to change your rule to drop the object_size_greater_than
(which would also allow you to drop the and
block)? So, like this:
filter {
prefix = "demo/"
}
I've been working with this resource recently and have noticed some funky behavior around some of the fields within and
, but for me this change works in local tests. It should be equivalent to what you have above. If I recall from Cloudtrail logs, I don't even think object_size_greater_than
gets set in the actual request unless it is greater than 0
, but I might be misremembering that.
A weird note about the Okay, bizarre, but this behavior seems to be different now. Now it isn't letting you get away with only having one field in the and
block and prefix
-- it seems that if you only use prefix
within and
without specifying anything else, you'll get a malformed xml error as well. Kindof weird. Seems like a bug in the AWS APIs.and
block, but I swear it was before. Weird. I did open a support case with them yesterday so maybe someone took care of it? lol
However if you really wanted to keep your original example, it also seems to work if you uncomment object_size_less_than
and make sure to set it to 1 or above. You could always set it to some insanely high number if you wanted to go that route in order to make sure it applies to every object, but really I would just try the change I mentioned above.
Hi @rvoh-tismith
Sorry for delay in response.
Actually, I don't want my S3 bucket lifecycle to delete the entire demo folder that why I am setting object_size_greater_than = 0 bytes and files should be deleted inside demo folder not the entire folder. Alos I have gone through below documentation for that.
https://repost.aws/questions/QU0aFOK4KZQQGos8iTc_W1Yw/s3-object-delete
For now I have applied below lifecycle policy using terraform and minimum object size I have explicitly changed through AWS console. It will be great help if we can achieve both condition using terraform only..
`resource "aws_s3_bucket" "lifecycle_test_bucket" { bucket = "lifecycle-test-bucket3210912" }
resource "aws_s3_bucket_lifecycle_configuration" "lifecycle_test_bucket" { bucket = aws_s3_bucket.lifecycle_test_bucket.id
rule { id = "rule-1" status = "Enabled" expiration { days = 1 } filter { prefix = "demo/" }
} }
status = "Enabled"
expiration {
days = 1
}
} }`
@pravinkhot123 Ah, I see. My bad, I thought maybe that was just included from an example or something. I see you're dealing with a bit of an edge case. I'm pretty sure this is because when filter.and.object_size_greater_than
is zero it doesn't actually get included in the request, so only filter.and.prefix
is getting set, and as I mentioned you're not allowed to only set one field in the and
block or you get malformed xml errors. I'm actually working on a PR that should fix this.
Terraform Core Version
v1.1.2
AWS Provider Version
5.6.2
Affected Resource(s)
aws_s3
Expected Behavior
All object older than once day should get deleted which are present under demo folder but demo folder should not get deleted.
Actual Behavior
Unable to set delete lifecycle configuration with two filters object_size_greater_than = 0 and prefix = "demo/"
Relevant Error/Panic Output Snippet
Terraform Configuration Files
Steps to Reproduce
I am using terraform version v1.1.2 AWS provider version 5.6.2
Debug Output
Panic Output
Important Factoids
No response
References
No response
Would you like to implement a fix?
None