github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/file.html.md (about) 1 --- 2 layout: "functions" 3 page_title: "file - Functions - Configuration Language" 4 sidebar_current: "docs-funcs-file-file-x" 5 description: |- 6 The file function reads the contents of the file at the given path and 7 returns them as a string. 8 --- 9 10 # `file` Function 11 12 -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and 13 earlier, see 14 [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html). 15 16 `file` reads the contents of a file at the given path and returns them as 17 a string. 18 19 ```hcl 20 file(path) 21 ``` 22 23 Strings in the Terraform language are sequences of Unicode characters, so 24 this function will interpret the file contents as UTF-8 encoded text and 25 return the resulting Unicode characters. If the file contains invalid UTF-8 26 sequences then this function will produce an error. 27 28 This function can be used only with files that already exist on disk 29 at the beginning of a Terraform run. Functions do not participate in the 30 dependency graph, so this function cannot be used with files that are generated 31 dynamically during a Terraform operation. We do not recommend using dynamic 32 local files in Terraform configurations, but in rare situations where this is 33 necessary you can use 34 [the `local_file` data source](/docs/providers/local/d/file.html) 35 to read files while respecting resource dependencies. 36 37 ## Examples 38 39 ``` 40 > file("${path.module}/hello.txt") 41 Hello World 42 ``` 43 44 ## Related Functions 45 46 * [`filebase64`](./filebase64.html) also reads the contents of a given file, 47 but returns the raw bytes in that file Base64-encoded, rather than 48 interpreting the contents as UTF-8 text. 49 * [`fileexists`](./fileexists.html) determines whether a file exists 50 at a given path. 51 * [`templatefile`](./templatefile.html) renders using a file from disk as a 52 template.