@ -37,39 +37,67 @@ before Packer takes any actions.
## Examples
```shell-session
> fileset(path.folder, "files/*.txt")
> tree pkr-consul
pkr-consul
├── build-linux.pkr.hcl
└── linux
├── files
│ ├── hello.txt
│ └── world.txt
└── scripts
├── script-1-install.sh
└── script-2-setup.sh
3 directories, 5 files
> fileset(".", "*") | packer console pkr-consul
[
"files/hello.txt",
"files/world.txt",
"build-linux.pkr.hcl",
]
> echo 'fileset(".", "linux/scripts/*")' | packer console pkr-consul
[
"linux/scripts/script-1-install.sh",
"linux/scripts/script-2-setup.sh",
]
> fileset(path.folder, "files/{hello,world}.txt")
> echo 'fileset("linux", "files/{hello,world}.txt")' | packer console pkr-consul
[
"files/hello.txt",
"files/world.txt",
]
> fileset("${path.folder}/files", "*")
> echo 'fileset("./linux/files", "*")' | packer console pkr-consul
[
"hello.txt",
"world.txt",
]
> fileset("${path.folder}/files", "**")
> echo 'fileset("./linux", "**")' | packer console pkr-consul
[
"hello.txt",
"world.txt",
"subdirectory/anotherfile.txt",
"files/hello.txt",
"files/world.txt",
"scripts/script-1-install.sh",
"scripts/script-2-setup.sh",
]
```
A common use of `fileset` is to create one resource instance per matched file, using
[the `for_each` meta-argument](https://www.terraform.io/docs/configuration/resources.html#for_each-multiple-resource-instances-defined-by-a-map-or-set-of-strings):
A common use of `fileset` is to set the `scripts` field of a `shell`
provisioner with a list of matching scripts to run.
```hcl
resource "example_thing" "example" {
for_each = fileset(path.folder, "files/*")
# other configuration using each.value
}
build {
sources = [
"source.amazon-ebs.linux",
]
provisioner "shell" {
scripts = fileset(".", "linux/scripts/*")
}
```
List of provisioners with a `scripts` field:
* [`shell`](/docs/provisioners/shell)
* [`powershell`](/docs/provisioners/powershell)
* [`shell-local`](/docs/provisioners/shell-local)
* [`windows-shell`](/docs/provisioners/windows-shell)