Packer
Path variables
This topic provides reference information about path variables for Packer templates written in HCL.
Description
Use the following variables to build paths:
path.cwd: the directory from where Packer was started.path.root: the directory of the input HCL file or the input folder.
Examples
locals {
settings_file = "${path.cwd}/settings.txt"
scripts_folder = "${path.root}/scripts"
root = path.root
}
Path separators
Separate paths with a forward slash (/), especially when using relative paths in your configuration.
Windows uses backward slashes (\) to separate paths, but Packer only recognizes / as path
separators when it creates builds from any non-Windows system. Packer also treat backslashes as plain text, which could lead to errors.
Related functions
abspathtakes a string containing a filesystem path and converts it to an absolute path.basenamereturns only the last portion of a filesystem path, discarding the portion that would be returned bydirname.filesetenumerates a set of regular file names given a path and pattern.dirnamereturns all of the segments of a filesystem path except the last, discarding the portion that would be returned bybasename.