Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Terraform if语句,带true或false_Terraform - Fatal编程技术网

Terraform if语句,带true或false

Terraform if语句,带true或false,terraform,Terraform,我需要准备if声明。我想知道什么是最好的解决办法 locals { prod_ingress_certyficate = "${prod_ingress_certyficate == "true" ? var.prod_cert : var.test_cert}" } 这是正确的方法吗?如果变量为true,则使用prod\u cert;如果为false,则使用test\u cert。在定义前,不能引用prod\u entres\u certyfic

我需要准备if声明。我想知道什么是最好的解决办法

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

这是正确的方法吗?如果变量为true,则使用prod\u cert;如果为false,则使用test\u cert。

在定义前,不能引用
prod\u entres\u certyficate
。但是,您可以创建一个名为
prod\u incress\u 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
}