Skip to main content

fileexists Function

fileexists determines whether a file exists at a given path.

Code Block

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 OpenTofu 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.


Code Block
> fileexists("${path.module}/hello.txt")
Code Block
fileexists("") ? file("") : local.default_content
  • file reads the contents of a file at a given path