如何让 Terraform archive_file 资源获取对源文件的更改?

Sho*_*orn 7 aws-lambda terraform

在 Win 10 机器上使用 TF 0.7.2。

我正在尝试使用 TF 0.7.1 中引入的新“archive_file”资源,为在 AWS 中开发我的 lambda 函数设置编辑/上传周期

我的配置是这样的:

resource "archive_file" "cloudwatch-sumo-lambda-archive" {
  source_file = "${var.lambda_src_dir}/cloudwatch/cloudwatchSumologic.js"
  output_path = "${var.lambda_gen_dir}/cloudwatchSumologic.zip"
  type = "zip"
}

resource "aws_lambda_function" "cloudwatch-sumo-lambda" {
  function_name = "cloudwatch-sumo-lambda"
  description = "managed by source project"
  filename = "${archive_file.cloudwatch-sumo-lambda-archive.output_path}"
  source_code_hash = "${archive_file.cloudwatch-sumo-lambda-archive.output_sha}"
  handler = "cloudwatchSumologic.handler"

  ...
}
Run Code Online (Sandbox Code Playgroud)

这在我第一次运行时有效 - TF 创建 lambda zip 文件,上传它并在 AWS 中创建 lambda。问题在于更新 lambda。

如果我在上面的示例中编辑 cloudwatchSumologic.js 文件,TF 似乎不知道源文件已更改 - 它不会将新文件添加到 zip 并且不会将新的 lambda 代码上传到 AWS。

我在配置中做错了什么,还是不打算以这种方式使用 archive_file 资源?

noc*_*ode 0

您可能会看到一个错误。我使用的是 0.7.7,现在的问题是 SHA 更改,即使您不进行更改也是如此。Hashicorp 将在 0.7.8 中将此资源更新为数据源

https://github.com/hashicorp/terraform/pull/8492