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

     1  ---
     2  page_title: fileset - Functions - Configuration Language
     3  description: The fileset function enumerates a set of regular file names given a pattern.
     4  ---
     5  
     6  # `fileset` Function
     7  
     8  `fileset` enumerates a set of regular file names given a path and pattern.
     9  The path is automatically removed from the resulting set of file names and any
    10  result still containing path separators always returns forward slash (`/`) as
    11  the path separator for cross-system compatibility.
    12  
    13  ```hcl
    14  fileset(path, pattern)
    15  ```
    16  
    17  Supported pattern matches:
    18  
    19  - `*` - matches any sequence of non-separator characters
    20  - `**` - matches any sequence of characters, including separator characters
    21  - `?` - matches any single non-separator character
    22  - `{alternative1,...}` - matches a sequence of characters if one of the comma-separated alternatives matches
    23  - `[CLASS]` - matches any single non-separator character inside a class of characters (see below)
    24  - `[^CLASS]` - matches any single non-separator character outside a class of characters (see below)
    25  
    26  Note that the doublestar (`**`) must appear as a path component by itself. A
    27  pattern such as /path\*\* is invalid and will be treated the same as /path\*, but
    28  /path\*/\*\* should achieve the desired result.
    29  
    30  Character classes support the following:
    31  
    32  - `[abc]` - matches any single character within the set
    33  - `[a-z]` - matches any single character within the range
    34  
    35  Functions are evaluated during configuration parsing rather than at apply time,
    36  so this function can only be used with files that are already present on disk
    37  before Terraform takes any actions.
    38  
    39  ## Examples
    40  
    41  ```
    42  > fileset(path.module, "files/*.txt")
    43  [
    44    "files/hello.txt",
    45    "files/world.txt",
    46  ]
    47  
    48  > fileset(path.module, "files/{hello,world}.txt")
    49  [
    50    "files/hello.txt",
    51    "files/world.txt",
    52  ]
    53  
    54  > fileset("${path.module}/files", "*")
    55  [
    56    "hello.txt",
    57    "world.txt",
    58  ]
    59  
    60  > fileset("${path.module}/files", "**")
    61  [
    62    "hello.txt",
    63    "world.txt",
    64    "subdirectory/anotherfile.txt",
    65  ]
    66  ```
    67  
    68  A common use of `fileset` is to create one resource instance per matched file, using
    69  [the `for_each` meta-argument](/language/meta-arguments/for_each):
    70  
    71  ```hcl
    72  resource "example_thing" "example" {
    73    for_each = fileset(path.module, "files/*")
    74  
    75    # other configuration using each.value
    76  }
    77  ```