Terraform:忽略对某个环境变量的更改
Terraform: ignore changes to a certain environment variable
我有一个使用 terraform 创建的 AWS Lambda 函数。代码更改是从我们的 CI-server 自动部署的,commit-sha 作为环境变量传递 (GIT_COMMIT_HASH
) - 所以这会更改 Terraform 之外的 Lambda 函数-范围(因为人们在问...).
到目前为止效果很好。但是现在我想更新函数的节点版本并且 terraform 尝试将 env var 重置为 "unknown"
.
的初始值
我尝试使用 ignore_changes
块,但无法让 terraform 忽略其他地方所做的更改...
resource "aws_lambda_function" "test" {
filename = data.archive_file.helloworld.output_path
function_name = "TestName_${var.environment}"
role = aws_iam_role.test.arn
handler = "src/index.handler"
runtime = "nodejs14.x"
timeout = 1
memory_size = 128
environment {
variables = {
GIT_COMMIT_HASH = "unknown"
}
}
lifecycle {
ignore_changes = [
environment.0.variables["GIT_COMMIT_HASH"],
]
}
}
这可能吗?我必须如何引用变量?
** 编辑 **
计划输出如下所示:
# aws_lambda_function.test will be updated in-place
~ resource "aws_lambda_function" "test" {
# ... removed some lines
source_code_size = 48012865
tags = {}
timeout = 1
version = "12"
~ environment {
~ variables = {
~ "GIT_COMMIT_HASH" = "b7a77d0" -> "unknown"
}
}
tracing_config {
mode = "PassThrough"
}
}
我有一个使用 terraform 创建的 AWS Lambda 函数。代码更改是从我们的 CI-server 自动部署的,commit-sha 作为环境变量传递 (GIT_COMMIT_HASH
) - 所以这会更改 Terraform 之外的 Lambda 函数-范围(因为人们在问...).
到目前为止效果很好。但是现在我想更新函数的节点版本并且 terraform 尝试将 env var 重置为 "unknown"
.
我尝试使用 ignore_changes
块,但无法让 terraform 忽略其他地方所做的更改...
resource "aws_lambda_function" "test" {
filename = data.archive_file.helloworld.output_path
function_name = "TestName_${var.environment}"
role = aws_iam_role.test.arn
handler = "src/index.handler"
runtime = "nodejs14.x"
timeout = 1
memory_size = 128
environment {
variables = {
GIT_COMMIT_HASH = "unknown"
}
}
lifecycle {
ignore_changes = [
environment.0.variables["GIT_COMMIT_HASH"],
]
}
}
这可能吗?我必须如何引用变量?
** 编辑 **
计划输出如下所示:
# aws_lambda_function.test will be updated in-place
~ resource "aws_lambda_function" "test" {
# ... removed some lines
source_code_size = 48012865
tags = {}
timeout = 1
version = "12"
~ environment {
~ variables = {
~ "GIT_COMMIT_HASH" = "b7a77d0" -> "unknown"
}
}
tracing_config {
mode = "PassThrough"
}
}