Reference specific map inside list

Is possible to access specific map in list?
My example is working, but I want to use something like jmespath.
${var.deployment.modules.vms[?name == \"foo\"]}
Is it possible?

variable "deployment" {
  type = object({
    name = string
    location = string
    tags = object({
      owner = string
    })
    modules = object({
       vms = list(object({
         name = string
       }))
    })
  })

  default = {
   name = "dummy"
   location = "dummy"
   tags = {
     owner = "dummy"
   }
   modules = {
     vms = [
       { name = "dummy" },
       { name = "foo"}
     ]
   }
  }
}




output "a" {
  value = "${element(var.deployment.modules.vms,0)}"
}

output "b" {
  value = "${var.deployment.modules.vms[0]}"
}

Thanks

Hi @lukasmrtvy!

There are some different ways to achieve the same result but the syntax can be a little convoluted. I’m not certain there is a straightforward function that looks up a map in a list. I used some list comprehension:

variable "deployment" {
  type = object({
    name = string
    location = string
    tags = object({
      owner = string
    })
    modules = object({
       vms = list(object({
         name = string
         test = string
       }))
    })
  })

  default = {
   name = "dummy"
   location = "dummy"
   tags = {
     owner = "dummy"
   }
   modules = {
     vms = [
       {
         name = "hello"
         test = "world"
       },
       { 
         name = "foo"
         test = "bar"
       }
     ]
   }
  }
}

output "a" {
  value =  [for index, vm in var.deployment.modules.vms: index if vm.test == "bar"]
}

output "b" {
  value =  [for index, vm in var.deployment.modules.vms: vm if vm.test == "bar"]
}