我有帶檔案的 terraform 模塊:main.tf variables.tf
在我定義的變數中:
variable "environment" {
type = string
description = "The environment the module is being deployed to, e.g: Test, Integrate or Production"
}
locals {
scale_in_protection = var.environment == "production" || "integrate" ? "true" : "false"
}
我收到此錯誤:
Releasing state lock. This may take a few moments...
?
│ Error: Invalid operand
│
│ on ..\..\modules\jitsi\variables.tf line 99, in locals:
│ 99: scale_in_protection = var.environment == "production" || "integrate" ? "true" : "false"
│
│ Unsuitable value for right operand: a bool is required.
uj5u.com熱心網友回復:
您的條件無效。它遺漏的比較var.environment和"integrate"。這是固定版本:
variable "environment" {
type = string
description = "The environment the module is being deployed to, e.g: Test, Integrate or Production"
}
locals {
scale_in_protection = var.environment == "production" || var.environment == "integrate" ? "true" : "false"
}
uj5u.com熱心網友回復:
我找到了解決我自己問題的方法:
scale_in_protection = contains(["production", "integrate"], var.environment) ? "true" : "false"
結果是 || 僅用于變數而不是字串,因此您需要使用包含。
https://www.terraform.io/docs/language/functions/contains.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/355137.html
