github.com/hashicorp/packer@v1.14.3/website/content/docs/templates/hcl_templates/path-variables.mdx (about)

     1  ---
     2  page_title: Path variables reference
     3  description: |-
     4    Path variables are special variables that enable you to provide directory information. Learn how to use path variables in Packer templates.
     5  ---
     6  
     7  # Path variables
     8  
     9  This topic provides reference information about path variables for Packer templates written in HCL.
    10  
    11  ## Description
    12  
    13  Use the following variables to build paths:  
    14  
    15  - `path.cwd`: the directory from where Packer was started.
    16  
    17  - `path.root`: the directory of the input HCL file or the input folder.
    18  
    19  ## Examples
    20  
    21  ```HCL
    22  locals {
    23    settings_file  = "${path.cwd}/settings.txt"
    24    scripts_folder = "${path.root}/scripts"
    25    root           = path.root
    26  }
    27  ```
    28  
    29  ## Path separators
    30  
    31  `@include 'path/separator-note.mdx'`
    32  
    33  ## Related functions
    34  
    35  - [`abspath`](/packer/docs/templates/hcl_templates/functions/file/abspath) takes a string containing
    36    a filesystem path and converts it to an absolute path.
    37  
    38  - [`basename`](/packer/docs/templates/hcl_templates/functions/file/basename) returns _only_ the last
    39    portion of a filesystem path, discarding the portion that would be returned
    40    by `dirname`.
    41  
    42  - [`fileset`](/packer/docs/templates/hcl_templates/functions/file/fileset) enumerates a set of
    43    regular file names given a path and pattern.
    44  
    45  - [`dirname`](/packer/docs/templates/hcl_templates/functions/file/dirname) returns all of the
    46    segments of a filesystem path _except_ the last, discarding the portion that
    47    would be returned by `basename`.