Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Terraform 在lambda_模块的预构建ZIP文件上计算源代码哈希?_Terraform_Terraform Provider Aws - Fatal编程技术网

Terraform 在lambda_模块的预构建ZIP文件上计算源代码哈希?

Terraform 在lambda_模块的预构建ZIP文件上计算源代码哈希?,terraform,terraform-provider-aws,Terraform,Terraform Provider Aws,我已经编写了一个terraform模块来创建一个Lambda,我很难弄清楚如何在预构建的ZIP文件上计算源代码散列。这将在管道中进行,因此每次都会生成ZIP文件,并且在我到达地形步骤之前可能会有所不同。 我正在用gulp(这是一个NodeJS应用程序)构建ZIP文件,并假设它是在目录中预构建的 build/myLambda.zip 基本上我想这样做。文件名是一个terraform变量,我希望源代码散列计算必须引用该文件 module my_lambda { filename = "${var

我已经编写了一个terraform模块来创建一个Lambda,我很难弄清楚如何在预构建的ZIP文件上计算源代码散列。这将在管道中进行,因此每次都会生成ZIP文件,并且在我到达地形步骤之前可能会有所不同。
我正在用gulp(这是一个NodeJS应用程序)构建ZIP文件,并假设它是在目录中预构建的 build/myLambda.zip

基本上我想这样做。文件名是一个terraform变量,我希望源代码散列计算必须引用该文件

module my_lambda {
  filename = "${var.my_zip_file}"
}
模块的相关部分包括:

resource "aws_lambda_function" "lambda" {
   filename            = "${var.filename}"
   source_code_hash    = "${filebase64sha256(file("${var.filename}"))}"
}
但是,当我运行terraform plan时,会出现以下错误:

Error: Error in function call

  on modules\lambda\main.tf line 16, in resource "aws_lambda_function" "lambda":
  16:     source_code_hash    = "${filebase64sha256(file("${var.filename}"))}"
    |----------------
    | var.filename is "build/myLambda.zip"

Call to function "file" failed: contents of
build/myLambda.zip are not valid UTF-8;
use the filebase64 function to obtain the Base64 encoded contents or the other
file functions (e.g. filemd5, filesha256) to obtain file hashing results
instead.
该函数类似于
base64sha256(文件(…)
,但通过将这两个函数组合在一起,它避免了创建文件内容的中间字符串的需要,从而避免了对文件进行UTF-8编码的要求

因此,您不需要调用
file
函数,因为读取文件内置于该函数中:

  source_code_hash = "${filebase64sha256(var.filename)}"

最新版本:
source\u code\u hash=filebase64sha256(var.filename)