I have an existing S3 bucket and I wish to add "folders" and lifecycle_rules to it.
(I say "folders" because that is how they are represented at the client end, as they are accessed via a Storage Gateway.)
I can create the folders, for example on to hold quarterly backups, like:
resource "aws_s3_bucket_object" "quarterly" {
bucket = "${var.bucket_id}"
acl = "private"
key = "quarterly"
source = "/dev/null"
}
But if I try and then add a lifecycle rule, as follows
resource "aws_s3_bucket" "quarterly" {
bucket = "${var.bucket_id}"
acl = "private"
lifecycle_rule {
id = "quarterly_retention"
prefix = "quarterly/"
enabled = true
tags {
"rule" = "quarterly"
}
expiration {
days = 92
}
}
}
I get an error when I do terraform apply.
* aws_s3_bucket.quarterly: Error creating S3 bucket: BucketAlreadyOwnedByYou: Your previous request to create the named bucket succeeded and you already own it.
status code: 409, request id: 702396A7D2FA28BA, host id: IJDA+vszRBYl4zmvW56dSnC2va2qpQXlfgeEL7X1QQHHv8eEaYKvSUCL0ZIj/VsdvQ2hkBLGjAY=
I want to create the bucket first and then add folders and lifecycle rules afterwards, rather than embed the lifecycle rules on creation.
Am I missing something, have I got it wrong?
Thanks for your help!