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