# Reference specific map inside list

**URL:** <https://discuss.hashicorp.com/t/reference-specific-map-inside-list/1665>\
**Category:** Terraform\
**Created:** [June 18, 2019, 11:22am UTC](https://discuss.hashicorp.com/t/reference-specific-map-inside-list/1665 "2019-06-18T11:22:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukasmrtvy](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/lukasmrtvy/32/1209_2.png) [@lukasmrtvy](https://discuss.hashicorp.com/u/lukasmrtvy)\
**Post date:** [June 18, 2019, 11:22am UTC](https://discuss.hashicorp.com/t/reference-specific-map-inside-list/1665/1 "2019-06-18T11:22:00Z")

</div>

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?

```auto
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

---

<div class="post-metadata">

**Author:** ![joatmon08](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/joatmon08/32/37342_2.png) [@joatmon08](https://discuss.hashicorp.com/u/joatmon08)\
**Post date:** [June 18, 2019, 4:22pm UTC](https://discuss.hashicorp.com/t/reference-specific-map-inside-list/1665/2 "2019-06-18T16:22:25Z")

</div>

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:

```auto
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"]
}

```
