amazon-web-services - terraform 未检测到对 lambda 源文件的更改
问题描述
在我的main.tf
我有以下内容:
data "template_file" "lambda_script_temp_file" {
template = "${file("../../../fn/lambda_script.py")}"
}
data "template_file" "library_temp_file" {
template = "${file("../../../library.py")}"
}
data "template_file" "init_temp_file" {
template = "${file("../../../__init__.py")}"
}
data "archive_file" "lambda_resources_zip" {
type = "zip"
output_path = "${path.module}/lambda_resources.zip"
source {
content = "${data.template_file.lambda_script_temp_file.rendered}"
filename = "lambda_script.py"
}
source {
content = "${data.template_file.library_temp_file.rendered}"
filename = "library.py"
}
source {
content = "${data.template_file.init_temp_file.rendered}"
filename = "__init__.py"
}
}
resource "aws_lambda_function" "MyLambdaFunction" {
filename = "${data.archive_file.lambda_resources_zip.output_path}"
function_name = "awesome_lambda"
role = "${var.my_role_arn}"
handler = "lambda_script.lambda_handler"
runtime = "python3.6"
timeout = "300"
}
问题是当我修改其中一个源文件时,例如lambda_script.py
,在新terraform apply
的lambda_resources_zip
.
我知道为了避免这种情况,我可以先运行terraform destroy
,但这不是我的用例的选项。
*我正在使用 Terraform v0.11.10
解决方案
我通过在资源定义中添加以下行解决了这个问题:
source_code_hash = "${data.archive_file.lambda_resources_zip.output_base64sha256}"
当源文件被修改时,散列值会改变并触发源文件被更新。
推荐阅读
- ruby-on-rails - 如何在 Rspec 功能规范中测试使用父记录的回调
- javascript - Apollo 本地查询不适用于变量
- firebase - 如何从 auth.user.onDelete 触发器中删除文档集合和所有嵌套数据
- minecraft - 使用 minecraft 参数自动连接到服务器
- c++ - 声明变量,其类型具有已删除的默认构造函数,没有值
- ios - 在滑动 Eureka 上更改“删除文本”
- java - if 语句可以简化吗?
- python - How to log for each script using logging (python)
- flutter - 防止容器填充 ReorderableListView 中的所有空间
- java - Androidx ViewPager2 不兼容类型:ViewPagerAdapter 无法转换为 Adapter