我在terraform构建的环境中调用了lambda:
$ sudo apt-get install sshpass
ansible server-group -m ping -k -u username
SSH password:
问题:该函数不仅在创建(“应用”)过程中被调用,而且在删除(“ destroy”)过程中也被调用。仅在创建期间如何调用它?我曾考虑过在lambda中检查环境变量(也许TF在这里添加了过程名称或类似名称),但我希望有更好的方法。
答案 0 :(得分:2)
-var 'lambda_xxx=execute'
选项,以检查是否需要执行lambda代码terraform docs lambda_xxx
,您可以在terraform代码中检查是否要运行lambda代码。resource "aws_waf_rule" "wafrule" {
depends_on = ["aws_waf_ipset.ipset"]
name = "${var.environment}-WAFRule"
metric_name = "${replace(var.environment, "-", "")}WAFRule"
count = "${var.is_waf_enabled == "true" ? 1 : 0}"
predicates {
data_id = "${aws_waf_ipset.ipset.id}"
negated = false
type = "IPMatch"
}
}
variables.tf
文件中声明的变量variable "is_waf_enabled" {
type = "string"
default = "false"
description = "String value to indicate if WAF/API KEY is turned on or off (true/any_value)"
}