• 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
        • Overview
          • abspath
          • basename
          • dirname
          • file
          • fileexists
          • fileset
          • pathexpand
          • templatefile
      • 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. Functions
  7. Filesystem Functions
  8. fileexists
  • Packer
  • v1.7.x
  • v1.6.x
  • v1.5.x

ยปfileexists Function

fileexists determines whether a file exists at a given path.

fileexists(path)

Functions are evaluated during configuration parsing rather than at apply time, so this function can only be used with files that are already present on disk before Packer takes any actions.

This function works only with regular files. If used with a directory, FIFO, or other special mode, it will return an error.

Examples

> fileexists("${path.folder}/hello.txt")
true
fileexists("custom-section.sh") ? file("custom-section.sh") : local.default_content

Related Functions

  • file reads the contents of a file at a given path.
Edit this page on GitHub

On this page

  1. fileexists Function
  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)