• HashiCorp Developer

  • HashiCorp Cloud Platform
  • Terraform
  • Packer
  • Consul
  • Vault
  • Boundary
  • Nomad
  • Waypoint
  • Vagrant
Packer
  • Install
  • Tutorials
  • Documentation
  • Guides
  • Plugins
  • Try Cloud(opens in new tab)
  • Sign up
Packer Home

Documentation

Skip to main content
  • Documentation
  • HCP Packer

  • Terminology
    • Overview
      • Overview
      • Variables
      • Locals
      • Contextual Variables
      • Data Sources
      • Path Variables
      • Syntax
      • Only Except
      • Expressions
      • JSON Syntax


  • Installing Packer
  • Configuring Packer

  • Integration Program

  • Debugging

  • Resources

  • Tutorial Library
  • Community Forum
    (opens in new tab)
  • Support
    (opens in new tab)
  • GitHub
    (opens in new tab)
  1. Developer
  2. Packer
  3. Documentation
  4. Templates
  5. HCL Templates
  6. Path Variables
  • Packer
  • v1.7.x
  • v1.6.x
  • v1.5.x

Note: If possible, try to always use a forward slash / as the path separator, especially when dealing with relative paths. A backward slash \ will work on Windows and is the official Windows path separator, but when building from any system that is not Windows, Packer will only treat slashes / as path separators, and treat backslashes as plain text. Which could lead to pathing errors.

ยปPath variables

  • 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
}

Related Functions

  • abspath takes a string containing a filesystem path and converts it to an absolute path.

  • basename returns only the last portion of a filesystem path, discarding the portion that would be returned by dirname.

  • fileset enumerates a set of regular file names given a path and pattern.

  • dirname returns all of the segments of a filesystem path except the last, discarding the portion that would be returned by basename.

Edit this page on GitHub

On this page

  1. Path variables
  2. Examples
  3. Related Functions
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)