I have upgraded a terraform root module from aws 3.7.x
to 4.3.x
, and have taken care of a few of the warnings. I had at existing aws_s3_bucket
, that was like so:
# AWS `3.7.x`, BEFORE upgrading to AWS `4.3.x` version
resource "aws_s3_bucket" "my_cool_bucket" {
bucket_prefix = "awesome"
acl = "private"
lifecycle {
prevent_destroy = true
}
versioning {
enabled = true
}
}
After upgrading to AWS 4.3.x
, I made this change and did terraform apply
# s3 bucket changes AFTER upgrading to AWS `4.3.x`
resource "aws_s3_bucket" "my_cool_bucket" {
bucket_prefix = "awesome"
lifecycle {
prevent_destroy = true
}
}
resource "aws_s3_bucket_acl" "my_cool_bucket_acl" {
bucket = aws_s3_bucket.my_cool_bucket.id
acl = "private"
}
resource "aws_s3_bucket_versioning" "my_cool_bucket_versioning" {
bucket = aws_s3_bucket.my_cool_bucket.id
versioning_configuration {
status = "Enabled"
}
}
so acl and versioning were extracted from the bucket - they were their in the aws_s3_bucket
resource in AWS 3 - and then I upgraded to AWS 4, and so now we have those "aws_s3_bucket_versioning"
and "aws_s3_bucket_acl"
resources in TF state and tied to the "aws_s3_bucket"
First of all, was my method above not correct, or was it OK?
Second, I still have over a dozen other “similar warnings” in terraform plan
s, that I feel must be related to my need to refactor the aws s3 bucket(since most of my resources don’t show deprecation changes in the CHANGELOG). If my method above is fine, how can I create a life cycle rule to prevent destroy, using the new "aws_s3_bucket_lifecycle_configuration"
resource? The documentation is a bit intricate [here].
Not sure how the code would be, below:
resource "aws_s3_bucket_lifecycle_configuration" "my_cool_bucket_lifecycle_configuration" {
bucket = aws_s3_bucket.bucket.id
rule {
# how would the rest of the code go?
status = "Enabled"
}
}
NOTE: The S3 refactor doc appears to be outdated, and since then things have been made backwards compatible. For the acl for example, TF says you will get an error, I did not get one when I upgraded from AWS 3 to 4:
You will get the following error after upgrading:
│ Error: Value for unconfigurable attribute
│
│ with aws_s3_bucket.example,
│ on main.tf line 1, in resource “aws_s3_bucket” “example”:
│ 1: resource “aws_s3_bucket” “example” {
│
│ Can’t configure a value for “acl”: its value will be decided automatically based on the result of applying this configuration.
The above didn’t happen. I just get warnings now and the upgrade to AWS 4 went through.
Reference docs I am aware of but may have missed something from:
aws_s3_bucket
- AWS 4 doc- S3 Bucket Refactor in AWS 4 upgrade guide