Terraform if语句为true或false

时间:2020-09-15 08:53:40

标签: terraform

我需要准备if语句。我想知道什么是最好的解决方案?

locals {
  prod_ingress_certyficate  = "${prod_ingress_certyficate == "true" ? var.prod_cert : var.test_cert}"
}

这是正确的方法吗?如果变量为true,则使用prod_cert;如果为false,则使用test_cert。

1 个答案:

答案 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
}