我想根据“app”和“db”层过滤 Terraform 中的字符串列表。但是, contains 函数返回空结果,其中包含字符串“app”
variable "tiers" {
type = list(string)
default = ["app-1", "app-2", "db-1", "db-2"]
}
output "iterate-apps" {
value = [
for app_id in var.tiers : app_id
if contains(["app"], app_id)
]
}
实际:
+ iterate-apps = []
预计:
iterate-apps = [ + "app-1", "app-2" ]
纠正我上面的代码有什么问题?
最好使用strcontains,而不是
contains
:
output "iterate-apps" {
value = [
for app_id in var.tiers : app_id
if strcontains(app_id, "app")
]
}