website/content/docs/templates/hcl_templates/functions/file/fileexists.mdx
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
[!IMPORTANT]
Documentation Update: Product documentation previously located in/websitehas moved to thehashicorp/web-unified-docsrepository, where all product documentation is now centralized. Please make contributions directly toweb-unified-docs, since changes to/websitein this repository will not appear on developer.hashicorp.com. ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
fileexists Functionfileexists 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.
> fileexists("${path.folder}/hello.txt")
true
fileexists("custom-section.sh") ? file("custom-section.sh") : local.default_content
file reads the contents
of a file at a given path.