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 "me too" comments, 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
Description
I miss a resource to add a lifecycle management rule to an existing S3 bucket. In our use-case, this bucket has to be created manually before Terraform applying. The "aws_s3_bucket" resource can't be used for this purpose.
I got this working by creating a null_resource and doing a AWS cli call "put-bucket-lifecycle-configuration" (see reference below) with the rule to be added in a template file. This is kind of hacky but works.
data "template_file" "lifecycle_rule_to_be_added" {
template = "${file("${path.module}/path/to/templates/lifecycle_rule_to_be_added.tpl")}"
vars = {
environment = "${var.environment}"
}
}
resource "null_resource" "add_lifecycle_rule" {
depends_on = [
"null_resource.add_lifecycle_rule",
]
provisioner "local-exec" {
command = "aws s3api put-bucket-lifecycle-configuration --bucket ${var.infrastructure_bucket} --lifecycle-configuration '${data.template_file.lifecycle_rule.rendered}'"
}
provisioner "local-exec" {
command = "aws s3api delete-bucket-lifecycle --bucket ${var.infrastructure_bucket}"
when = "destroy"
}
}
It would be nice to have a resource (for example "aws_s3_bucket_udpate") which let's you update certain properties of a given S3 bucket (assuming you have the right role). The api could be similar to the "aws_s3_bucket" resource.
I guess there are also other properties of a S3 that users would like to add or update.
New or Affected Resource(s)
aws_s3_bucket_update
References
Community Note
Description
I miss a resource to add a lifecycle management rule to an existing S3 bucket. In our use-case, this bucket has to be created manually before Terraform applying. The "aws_s3_bucket" resource can't be used for this purpose.
I got this working by creating a null_resource and doing a AWS cli call "put-bucket-lifecycle-configuration" (see reference below) with the rule to be added in a template file. This is kind of hacky but works.
It would be nice to have a resource (for example "aws_s3_bucket_udpate") which let's you update certain properties of a given S3 bucket (assuming you have the right role). The api could be similar to the "aws_s3_bucket" resource.
I guess there are also other properties of a S3 that users would like to add or update.
New or Affected Resource(s)
aws_s3_bucket_update
References