github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/website/docs/language/functions/fileset.html.md (about) 1 --- 2 layout: "language" 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 `fileset` enumerates a set of regular file names given a path and pattern. 12 The path is automatically removed from the resulting set of file names and any 13 result still containing path separators always returns forward slash (`/`) as 14 the path separator for cross-system compatibility. 15 16 ```hcl 17 fileset(path, pattern) 18 ``` 19 20 Supported pattern matches: 21 22 - `*` - matches any sequence of non-separator characters 23 - `**` - matches any sequence of characters, including separator characters 24 - `?` - matches any single non-separator character 25 - `{alternative1,...}` - matches a sequence of characters if one of the comma-separated alternatives matches 26 - `[CLASS]` - matches any single non-separator character inside a class of characters (see below) 27 - `[^CLASS]` - matches any single non-separator character outside a class of characters (see below) 28 29 Note that the doublestar (`**`) must appear as a path component by itself. A 30 pattern such as /path** is invalid and will be treated the same as /path*, but 31 /path*/** should achieve the desired result. 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/language/meta-arguments/for_each.html): 73 74 ```hcl 75 resource "example_thing" "example" { 76 for_each = fileset(path.module, "files/*") 77 78 # other configuration using each.value 79 } 80 ```