Terraform 包含的功能未按预期工作

问题描述 投票:0回答:1

我想根据“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" ]

纠正我上面的代码有什么问题?

terraform terraform-modules
1个回答
0
投票

最好使用strcontains,而不是

contains

output "iterate-apps" {
  value = [
    for app_id in var.tiers : app_id
    if strcontains(app_id, "app")    
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.