从 Terraform Cloud 获取变量值

Get variable value from terraform cloud

我有数据结果:

test = [
      + {
          + category  = "terraform"
          + hcl       = false
          + id        = "var-1adsJ88M"
          + name      = "myValue"
          + sensitive = false
          + value     = "keys"
        },
      + {
          + category  = "terraform"
          + hcl       = false
          + id        = "var-WcFasdas1"
          + name      = "potoken"
          + sensitive = false
          + value     = "b6adasd222gt5Nh("
        }
       ]

如何获取特定名称的值。

示例:我需要从名称 myValue 中获取值。这个名字可以在任何位置,我需要搜索数组

我的尝试:

output "variables_cloud" {
  value = data.tfe_variables.test.variables[*].name == "myValue"
}

最简单的方法是迭代搜索:

locals {
    test = [
           {
               category  = "terraform"
               hcl       = false
               id        = "var-1adsJ88M"
               name      = "myValue"
               sensitive = false
               value     = "keys"
            },
           {
               category  = "terraform"
               hcl       = false
               id        = "var-WcFasdas1"
               name      = "potoken"
               sensitive = false
               value     = "b6adasd222gt5Nh("
            }
           ]
           
    value_found = [for a_map in local.test: a_map.value if a_map.name == "myValue"][0]
}