Jav*_*sVA 2 terraform terraform-provider-aws
我已经编写了一个 terraform 模块来创建一个 Lambda,但我无法弄清楚如何在预构建的 ZIP 文件上计算 source_code_hash。这将在管道中,因此每次都会构建 ZIP 文件,并且在我到达 terraform 步骤之前可能会有所不同。
我正在使用 gulp 构建 ZIP 文件(这是一个 NodeJS 应用程序)并假设它是在目录 build/myLambda.zip 中预先构建的
基本上我想这样做。文件名是一个 terraform 变量,我希望 source_code_hash 计算必须引用该文件。
module my_lambda {
filename = "${var.my_zip_file}"
}
Run Code Online (Sandbox Code Playgroud)
该模块的相关部分是:
resource "aws_lambda_function" "lambda" {
filename = "${var.filename}"
source_code_hash = "${filebase64sha256(file("${var.filename}"))}"
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行 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.
Run Code Online (Sandbox Code Playgroud)
The filebase64sha256
function is similar to base64sha256(file(...))
, but by combining the two functions together it avoids the need to create an intermediate string of the file contents and thus avoids the requirement that the file be UTF-8 encoded.
Therefore you don't need the file
function call, because reading the file is built in to that function:
source_code_hash = "${filebase64sha256(var.filename)}"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1501 次 |
最近记录: |