我在更新存储桶 S3 时尝试使用 etag
,但出现此错误:
Error: Error in function call
on config.tf line 48, in resource "aws_s3_bucket_object" "bucket_app":
48: etag = filemd5("${path.module}/${var.env}/app-config.json")
|----------------
| path.module is "."
| var.env is "develop"
Call to function "filemd5" failed: no file exists at develop/app-config.json.
但是,这工作正常:
resource "aws_s3_bucket_object" "bucket_app" {
bucket = "${var.app}-${var.env}-app-assets"
key = "config.json"
source = "${path.module}/${var.env}/app-config.json"
// etag = filemd5("${path.module}/${var.env}/app-config.json")
depends_on = [
local_file.app_config_json
]
}
我正在以这种方式生成文件:
resource "local_file" "app_config_json" {
content = local.app_config_json
filename = "${path.module}/${var.env}/app-config.json"
}
我真的不明白我做错了什么......
最佳答案
如果您碰巧到达此处并使用 archive_file
数据源,则有一个名为 output_md5
的导出属性。这似乎提供了与 filemd5(data.archive_file.app_config_json.output_path)
相同的结果。
这是一个完整的例子:
data archive_file config {
type = "zip"
output_path = "${path.module}/config.zip"
source {
filename = "config/template-configuration.json"
content = "some content"
}
}
resource aws_s3_bucket_object config{
bucket = aws_s3_bucket.stacks.bucket
key = "config.zip"
content_type = "application/zip"
source = data.archive_file.config.output_path
etag = data.archive_file.config.output_md5
}
关于terraform - 尝试使用 etag 时找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62134028/