Terraform
CARVIEW |
Select Language
HTTP/2 308
cache-control: public, max-age=0, must-revalidate
content-type: text/plain
date: Thu, 24 Jul 2025 17:37:19 GMT
location: https://developer.hashicorp.com/terraform/language/functions/file
refresh: 0;url=https://developer.hashicorp.com/terraform/language/functions/file
server: Vercel
strict-transport-security: max-age=63072000
x-vercel-id: bom1::hh5lh-1753378639504-1aa61b75b772
HTTP/2 200
age: 417
cache-control: public, max-age=0, must-revalidate
content-encoding: gzip
content-type: text/html; charset=utf-8
date: Thu, 24 Jul 2025 15:12:37 GMT
etag: W/"8l6qx2egm13ab4"
server: Vercel
set-cookie: hc_geo=country%3DIN%2Cregion%3DKA; Path=/; Expires=Thu, 31 Jul 2025 17:37:19 GMT; Max-Age=604800
strict-transport-security: max-age=63072000
x-frame-options: SAMEORIGIN
x-matched-path: /terraform/language/[[...page]]
x-powered-by: Next.js
x-vercel-cache: STALE
x-vercel-id: bom1::sfo1::bqnc6-1753378639663-a7e359e6ab00
file - Functions - Configuration Language | Terraform | HashiCorp Developer Edit this page on GitHub
file Function
file
reads the contents of a file at the given path and returns them as
a string.
file(path)
Strings in the Terraform language are sequences of Unicode characters, so this function will interpret the file contents as UTF-8 encoded text and return the resulting Unicode characters. If the file contains invalid UTF-8 sequences then this function will produce an error.
This function can be used only with files that already exist on disk
at the beginning of a Terraform run. Functions do not participate in the
dependency graph, so this function cannot be used with files that are generated
dynamically during a Terraform operation. We do not recommend using dynamic
local files in Terraform configurations, but in rare situations where this is
necessary you can use
the local_file
data source
to read files while respecting resource dependencies.
Examples
> file("${path.module}/hello.txt")
Hello World
Related Functions
filebase64
also reads the contents of a given file, but returns the raw bytes in that file Base64-encoded, rather than interpreting the contents as UTF-8 text.fileexists
determines whether a file exists at a given path.templatefile
renders using a file from disk as a template.