我需要准备if语句。我想知道什么是最好的解决方案?
locals {
prod_ingress_certyficate = "${prod_ingress_certyficate == "true" ? var.prod_cert : var.test_cert}"
}
这是正确的方法吗?如果变量为true,则使用prod_cert;如果为false,则使用test_cert。
答案 0 :(得分:2)
在定义prod_ingress_certyficate
之前不能引用它。但是,您可以创建一个名为prod_ingress_certyficate
的变量,然后根据情况在locals
中使用它:
variable "prod_cert" {
default = "prod_cert"
}
variable "test_cert" {
default = "test_cert"
}
variable "prod_ingress_certyficate" {
default = true
}
locals {
prod_ingress_certyficate = var.prod_ingress_certyficate == true ? var.prod_cert : var.test_cert
}
output "test" {
value = local.prod_ingress_certyficate
}