github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/fileexists.html.md (about) 1 --- 2 layout: "functions" 3 page_title: "fileexists - Functions - Configuration Language" 4 sidebar_current: "docs-funcs-file-file-exists" 5 description: |- 6 The fileexists function determines whether a file exists at a given path. 7 --- 8 9 # `fileexists` Function 10 11 -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and 12 earlier, see 13 [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html). 14 15 `fileexists` determines whether a file exists at a given path. 16 17 ```hcl 18 fileexists(path) 19 ``` 20 21 Functions are evaluated during configuration parsing rather than at apply time, 22 so this function can only be used with files that are already present on disk 23 before Terraform takes any actions. 24 25 This function works only with regular files. If used with a directory, FIFO, 26 or other special mode, it will return an error. 27 28 ## Examples 29 30 ``` 31 > fileexists("${path.module}/hello.txt") 32 true 33 ``` 34 35 ```hcl 36 fileexists("custom-section.sh") ? file("custom-section.sh") : local.default_content 37 ``` 38 39 ## Related Functions 40 41 * [`file`](./file.html) reads the contents of a file at a given path