github.com/iaas-resource-provision/iaas-rpc@v1.0.7-0.20211021023331-ed21f798c408/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 Character classes support the following: 30 31 - `[abc]` - matches any single character within the set 32 - `[a-z]` - matches any single character within the range 33 34 Functions are evaluated during configuration parsing rather than at apply time, 35 so this function can only be used with files that are already present on disk 36 before Terraform takes any actions. 37 38 ## Examples 39 40 ``` 41 > fileset(path.module, "files/*.txt") 42 [ 43 "files/hello.txt", 44 "files/world.txt", 45 ] 46 47 > fileset(path.module, "files/{hello,world}.txt") 48 [ 49 "files/hello.txt", 50 "files/world.txt", 51 ] 52 53 > fileset("${path.module}/files", "*") 54 [ 55 "hello.txt", 56 "world.txt", 57 ] 58 59 > fileset("${path.module}/files", "**") 60 [ 61 "hello.txt", 62 "world.txt", 63 "subdirectory/anotherfile.txt", 64 ] 65 ``` 66 67 A common use of `fileset` is to create one resource instance per matched file, using 68 [the `for_each` meta-argument](/docs/language/meta-arguments/for_each.html): 69 70 ```hcl 71 resource "example_thing" "example" { 72 for_each = fileset(path.module, "files/*") 73 74 # other configuration using each.value 75 } 76 ```