2

I have data result:

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("
        }
       ]

How to get value a specific name.

Example: I need get value from of name myValue. This name can be in any position, I need to search the array

My attempts:

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

1 Answer 1

3

The easiest way is to search iteratively:

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]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.