github.com/hugorut/terraform@v1.1.3/website/docs/language/functions/formatlist.mdx (about)

     1  ---
     2  page_title: formatlist - Functions - Configuration Language
     3  description: |-
     4    The formatlist function produces a list of strings by formatting a number of
     5    other values according to a specification string.
     6  ---
     7  
     8  # `formatlist` Function
     9  
    10  `formatlist` produces a list of strings by formatting a number of other
    11  values according to a specification string.
    12  
    13  ```hcl
    14  formatlist(spec, values...)
    15  ```
    16  
    17  The specification string uses
    18  [the same syntax as `format`](/language/functions/format#specification-syntax).
    19  
    20  The given values can be a mixture of list and non-list arguments. Any given
    21  lists must be the same length, which decides the length of the resulting list.
    22  
    23  The list arguments are iterated together in order by index, while the non-list
    24  arguments are used repeatedly for each iteration. The format string is evaluated
    25  once per element of the list arguments.
    26  
    27  ## Examples
    28  
    29  ```
    30  > formatlist("Hello, %s!", ["Valentina", "Ander", "Olivia", "Sam"])
    31  [
    32    "Hello, Valentina!",
    33    "Hello, Ander!",
    34    "Hello, Olivia!",
    35    "Hello, Sam!",
    36  ]
    37  > formatlist("%s, %s!", "Salutations", ["Valentina", "Ander", "Olivia", "Sam"])
    38  [
    39    "Salutations, Valentina!",
    40    "Salutations, Ander!",
    41    "Salutations, Olivia!",
    42    "Salutations, Sam!",
    43  ]
    44  ```
    45  
    46  ## Related Functions
    47  
    48  * [`format`](/language/functions/format) defines the specification syntax used by this
    49    function and produces a single string as its result.