You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
packer/website/content/docs/templates/hcl_templates/path-variables.mdx

53 lines
2.0 KiB

---
page_title: Path variables reference
description: |-
Path variables are special variables that enable you to provide directory information. Learn how to use path variables in Packer templates.
---
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
> [!IMPORTANT]
> **Documentation Update:** Product documentation previously located in `/website` has moved to the [`hashicorp/web-unified-docs`](https://github.com/hashicorp/web-unified-docs) repository, where all product documentation is now centralized. Please make contributions directly to `web-unified-docs`, since changes to `/website` in this repository will not appear on developer.hashicorp.com.
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
# 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
```HCL
locals {
settings_file = "${path.cwd}/settings.txt"
scripts_folder = "${path.root}/scripts"
root = path.root
}
```
## Path separators
`@include 'path/separator-note.mdx'`
## Related functions
- [`abspath`](/packer/docs/templates/hcl_templates/functions/file/abspath) takes a string containing
a filesystem path and converts it to an absolute path.
- [`basename`](/packer/docs/templates/hcl_templates/functions/file/basename) returns _only_ the last
portion of a filesystem path, discarding the portion that would be returned
by `dirname`.
- [`fileset`](/packer/docs/templates/hcl_templates/functions/file/fileset) enumerates a set of
regular file names given a path and pattern.
- [`dirname`](/packer/docs/templates/hcl_templates/functions/file/dirname) returns all of the
segments of a filesystem path _except_ the last, discarding the portion that
would be returned by `basename`.