-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to migrate from r/aws_s3_bucket_object → r/aws_s3_object #25412
Comments
Hey @grimm26 👋 Thank you for taking the time to raise this, and I'm sorry to hear you're having some troubles with the migration. You've nailed the potential paths forward, but for completeness, I'll link to the appropriate section of the v4 upgrade guide. Essentially, there's three possible options:
As far as why this route was taken rather than aliasing, we had a pretty length discussion with the community around these changes over on #23106, where we discussed the paths we considered, and why we ultimately decided to go this route. I hope that conversation can provide a bit of additional clarity around that decision. We recognize that this change was fairly large and caused a bit of pain to the user experience, and hope to not have to make changes like this too often (which is why we limit them to around once a year, during major version releases), but felt that it was necessary in order to ensure the continued maintainability and functionality of the provider going forward. |
@justinretzolk my particular pain in this is that I have a module that we use to create lambdas and it "provisions" the I've read that section of the upgrade guide and there is no automation for this. The cleanest way would seem to be doing a There is no discussion of |
This doesn't seem to work. We started with
So I made a new resource with same values:
Then ran Terraform says it was imported fine but it doesn't actually seem to import much of anything as it wants to modify nearly all the attributes on next apply.
This means I have to manually edit the state, basically copying the attributes from the previous one. For every single S3 object. Unless I want it to outright replace the object which has various consequences like running event bridge rules and such. This seems very similar to #17791 except even more annoying to fix as it's not just a couple of deprecated attributes. |
When I replaced |
Assuming re-creating the S3 objects is an option, a possible workaround for migrating a Let's assume that our initial state is: locals {
items = ["foo", "bar", "bas", "xip", "a", "b", "c", "x", "y", "z"]
}
resource "aws_s3_bucket_object" "this" {
for_each = toset(local.items)
bucket = "mybucket"
key = each.key
content = each.value
} First, we locals {
items = ["foo", "bar", "bas", "xip", "a", "b", "c", "x", "y", "z"]
}
resource "aws_s3_bucket_object" "this" {
for_each = toset([])
bucket = "mybucket"
key = each.key
content = each.value
}
resource "aws_s3_object" "this" {
depends_on = [
aws_s3_bucket_object.this
]
for_each = toset(local.items)
bucket = "mybucket"
key = each.key
content = each.value
} This will remove the In the next With Terraform v1.1 or newer, we can also do the above for a single resource: Let's assume that our initial state is: resource "aws_s3_bucket_object" "this" {
bucket = "mybucket"
key = each.key
content = each.value
} First, we moved {
from = aws_s3_bucket_object.this
to = aws_s3_bucket_object.this[0]
}
resource "aws_s3_bucket_object" "this" {
count = 0
bucket = "mybucket"
key = each.key
content = each.value
}
resource "aws_s3_object" "this" {
depends_on = [
aws_s3_bucket_object.this
]
bucket = "mybucket"
key = each.key
content = each.value
} This will remove the In the next The |
I ended up biting the bullet and just going through my state files and changing |
I've added this note to 17791, but putting it here as well for added exposure. When importing an existing S3 bucket, acl & force_destory are missing. Terraform tries to add these to the existing objects. To ignore this, add this to the aws_s3_object resource. The alternative is to edit the state file, which I'm not a fan of doing.
|
Hopefully the resource will be updated for the new feature in Terraform 1.8:
|
More information about this: hashicorp/terraform-plugin-framework#917 |
We all know there is a decent amount of pain involved in making the jump from v3 of the aws provider to v4 with regards to s3 bucket resources, but I’ve hit a bit of a roadblock with r/aws_s3_bucket_object → r/aws_s3_object. Basically, there seems to be no way around doing some sort of manual intervention of either removing the old resource from state and then importing the new one, or the actual manual editing of the state file to just change the resource from aws_s3_bucket_object to aws_s3_object.
Why is this resource not just aliased? Like aws_alb and aws_lb are the same thing. Keep the deprecation message for aws_s3_bucket_object, but let it live on where needed.
The text was updated successfully, but these errors were encountered: