aws_s3_bucket_object 已弃用,我是否应该仅使用 aws_s3_bucket 上传文件?

With aws_s3_bucket_object deprecated, should I upload files using aws_s3_bucket only?

aws_s3_bucket_object 页面上有一条注释说它已被弃用,请改用 aws_s3_bucket

The aws_s3_bucket_object resource is DEPRECATED and will be removed in a future version! Use aws_s3_object instead, where new features and fixes will be added. When replacing aws_s3_bucket_object with aws_s3_object in your configuration, on the next apply, Terraform will recreate the object. If you prefer to not have Terraform recreate the object, import the object using aws_s3_object.

当我转到 aws_s3_bucket 页面时,没有关于如何上传文件的示例,只有关于如何创建存储桶的示例。网上很多文章也指出使用aws_s3_bucket创建bucket,但仍然使用aws_s3_bucket_object上传文件,这还是正确的做法吗?

如果您查看 aws_s3_object and compare it to the documentation of the older aws_s3_bucket_object 的文档,您会发现它们非常相似。如果您正在使用 Terraform 的一些在线教程,将代码中的 aws_s3_bucket_object 切换为 aws_s3_object 可能不会出现重大问题。

显然,如果您已经应用了计划并决定将 aws_s3_bucket_object 切换为 aws_s3_object,您将面临问题。在这种情况下,您需要 import 对象进入当前状态。

目前最新的 AWS 提供程序是 4.9.0,它标记 aws_s3_bucket_object 已弃用,但并未删除。只要您不打算升级提供程序,您的代码就可以工作。如果你想 future-proof 你的代码,你需要使用 aws_s3_object.