github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/fileset.html.md (about) 1 --- 2 layout: "functions" 3 page_title: "fileset - Functions - Configuration Language" 4 sidebar_current: "docs-funcs-file-file-set" 5 description: |- 6 The fileset function enumerates a set of regular file names given a pattern. 7 --- 8 9 # `fileset` 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 `fileset` enumerates a set of regular file names given a path and pattern. 16 The path is automatically removed from the resulting set of file names and any 17 result still containing path separators always returns forward slash (`/`) as 18 the path separator for cross-system compatibility. 19 20 ```hcl 21 fileset(path, pattern) 22 ``` 23 24 Supported pattern matches: 25 26 - `*` - matches any sequence of non-separator characters 27 - `**` - matches any sequence of characters, including separator characters 28 - `?` - matches any single non-separator character 29 - `{alternative1,...}` - matches a sequence of characters if one of the comma-separated alternatives matches 30 - `[CLASS]` - matches any single non-separator character inside a class of characters (see below) 31 - `[^CLASS]` - matches any single non-separator character outside a class of characters (see below) 32 33 Character classes support the following: 34 35 - `[abc]` - matches any single character within the set 36 - `[a-z]` - matches any single character within the range 37 38 Functions are evaluated during configuration parsing rather than at apply time, 39 so this function can only be used with files that are already present on disk 40 before Terraform takes any actions. 41 42 ## Examples 43 44 ``` 45 > fileset(path.module, "files/*.txt") 46 [ 47 "files/hello.txt", 48 "files/world.txt", 49 ] 50 51 > fileset(path.module, "files/{hello,world}.txt") 52 [ 53 "files/hello.txt", 54 "files/world.txt", 55 ] 56 57 > fileset("${path.module}/files", "*") 58 [ 59 "hello.txt", 60 "world.txt", 61 ] 62 63 > fileset("${path.module}/files", "**") 64 [ 65 "hello.txt", 66 "world.txt", 67 "subdirectory/anotherfile.txt", 68 ] 69 ``` 70 71 A common use of `fileset` is to create one resource instance per matched file, using 72 [the `for_each` meta-argument](/docs/configuration/resources.html#for_each-multiple-resource-instances-defined-by-a-map-or-set-of-strings): 73 74 ```hcl 75 resource "example_thing" "example" { 76 for_each = fileset(path.module, "files/*") 77 78 # other configuration using each.value 79 } 80 ```