gpt4 book ai didi

amazon-web-services - Terraform S3 Bucket 对象的 etag 在每次应用时不断更新

转载 作者:行者123 更新时间:2023-12-02 05:32:16 24 4
gpt4 key购买 nike

我正在将 AWS Lambda 代码作为 zip 文件上传到 S3 存储桶中。

我有一个为 S3 存储桶对象声明的资源:

resource "aws_s3_bucket_object" "source-code-object" {
bucket = "${aws_s3_bucket.my-bucket.id}"
key = "source-code.zip"
source = "lambda_source_code/source-code.zip"
etag = "${base64sha256(file("lambda_source_code/source-code.zip"))}"
}

我还有一个数据声明来压缩我的代码:

data "archive_file" "source-code-zip" {
type = "zip"
source_file = "${path.module}/lambda_source_code/run.py"
output_path = "${path.module}/lambda_source_code/source-code.zip"
}

terraform apply 输出不断向我显示哈希值的更改:

  ~ aws_s3_bucket_object.source-code-object
etag: "old_hash" => "new_hash"

尽管我的源代码中没有任何变化。为什么会出现这种行为?我见过similar posts Lambdas 的源代码不断变化,但我的 Lambdas 实际上并不是每次都更新(在控制台中检查上次更新时间)。但是,看起来确实会在每次 apply 时上传一个新的 S3 存储桶对象。

最佳答案

默认情况下,您的 S3 存储桶可能使用 KMS key 来应用加密。以这种方式配置时,etag 不是文件内容 ( doc ) 的 MD5。

Objects created by the PUT Object, POST Object, or Copy operation, or through the AWS Management Console, and are encrypted by SSE-C or SSE-KMS, have ETags that are not an MD5 digest of their object data.

如果不知道他们的哈希实现,就无法预先计算 terraform 的值并使其成为稳定的计划。

相反,您应该使用 source_hash属性来解决限制。

关于amazon-web-services - Terraform S3 Bucket 对象的 etag 在每次应用时不断更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54330751/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com