github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/website/docs/language/functions/file.html.md (about)

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