github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/lookup.html.md (about)

     1  ---
     2  layout: "functions"
     3  page_title: "lookup - Functions - Configuration Language"
     4  sidebar_current: "docs-funcs-collection-lookup"
     5  description: |-
     6    The lookup function retrieves an element value from a map given its key.
     7  ---
     8  
     9  # `lookup` Function
    10  
    11  -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and
    12  earlier, see
    13  [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html).
    14  
    15  `lookup` retrieves the value of a single element from a map, given its key.
    16  If the given key does not exist, a the given default value is returned instead.
    17  
    18  ```
    19  lookup(map, key, default)
    20  ```
    21  
    22  -> For historical reasons, the `default` parameter is actually optional. However,
    23  omitting `default` is deprecated since v0.7 because that would then be
    24  equivalent to the native index syntax, `map[key]`.
    25  
    26  ## Examples
    27  
    28  ```
    29  > lookup({a="ay", b="bee"}, "a", "what?")
    30  ay
    31  > lookup({a="ay", b="bee"}, "c", "what?")
    32  what?
    33  ```
    34  
    35  ## Related Functions
    36  
    37  * [`element`](./element.html) retrieves a value from a _list_ given its _index_.