fileset 함수
fileset 함수
fileset는 경로와 패턴이 주어지면 정규 파일 이름의 집합을 열거해요. 결과 파일 이름 집합에서 경로는 자동으로 제거되고, 경로 구분자를 여전히 포함하는 결과는 크로스 시스템 호환성을 위해 항상 슬래시(/)를 경로 구분자로 반환해요.
fileset(path, pattern)
지원되는 패턴 매칭:
*— 구분자가 아닌 문자의 모든 시퀀스와 일치**— 구분자 문자를 포함한 모든 문자의 모든 시퀀스와 일치?— 구분자가 아닌 단일 문자와 일치{alternative1,...}— 콤마로 구분된 대안 중 하나가 일치하면 해당 문자 시퀀스와 일치[CLASS]— 문자 클래스(class) 안의 구분자가 아닌 단일 문자와 일치 (아래 참고)[^CLASS]— 문자 클래스 밖의 구분자가 아닌 단일 문자와 일치 (아래 참고)
문자 클래스는 다음을 지원해요.
[abc]— 집합 안의 단일 문자와 일치[a-z]— 범위 안의 단일 문자와 일치
함수는 적용(apply) 시점이 아니라 설정 파싱 중에 평가되므로, 이 함수는 Packer가 어떤 작업을 하기 전에 이미 디스크에 존재하는 파일에만 사용할 수 있어요.
출처: Packer 공식 문서
본문
예시 (Examples)
> 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
[
"build-linux.pkr.hcl",
]
> echo 'fileset(".", "linux/scripts/*")' | packer console pkr-consul
[
"linux/scripts/script-1-install.sh",
"linux/scripts/script-2-setup.sh",
]
> echo 'fileset("linux", "files/{hello,world}.txt")' | packer console pkr-consul
[
"files/hello.txt",
"files/world.txt",
]
> echo 'fileset("./linux/files", "*")' | packer console pkr-consul
[
"hello.txt",
"world.txt",
]
> echo 'fileset("./linux", "**")' | packer console pkr-consul
[
"files/hello.txt",
"files/world.txt",
"scripts/script-1-install.sh",
"scripts/script-2-setup.sh",
]
fileset의 흔한 용도는 실행할 일치하는 스크립트 목록으로 shell provisioner의 scripts 필드를 설정하는 것이에요.
build {
sources = [
"source.amazon-ebs.linux",
]
provisioner "shell" {
scripts = fileset(".", "linux/scripts/*")
}
scripts 필드가 있는 provisioner 목록:
shellpowershellshell-localwindows-shell