github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/filebase64.html.md (about)

     1  ---
     2  layout: "functions"
     3  page_title: "filebase64 - Functions - Configuration Language"
     4  sidebar_current: "docs-funcs-file-filebase64"
     5  description: |-
     6    The filebase64 function reads the contents of the file at the given path and
     7    returns them as a base64-encoded string.
     8  ---
     9  
    10  # `filebase64` 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  `filebase64` reads the contents of a file at the given path and returns them as
    17  a base64-encoded string.
    18  
    19  ```hcl
    20  filebase64(path)
    21  ```
    22  
    23  The result is a Base64 representation of the raw bytes in the given file.
    24  Strings in the Terraform language are sequences of Unicode characters, so
    25  Base64 is the standard way to represent raw binary data that cannot be
    26  interpreted as Unicode characters. Resource types that operate on binary
    27  data will accept this data encoded in Base64, thus avoiding the need to
    28  decode the result of this function.
    29  
    30  Terraform uses the "standard" Base64 alphabet as defined in
    31  [RFC 4648 section 4](https://tools.ietf.org/html/rfc4648#section-4).
    32  
    33  This function can be used only with functions that already exist as static
    34  files on disk at the beginning of a Terraform run. Language functions do not
    35  participate in the dependency graph, so this function cannot be used with
    36  files that are generated dynamically during a Terraform operation.
    37  
    38  ## Examples
    39  
    40  ```
    41  > filebase64("${path.module}/hello.txt")
    42  SGVsbG8gV29ybGQ=
    43  ```
    44  
    45  ## Related Functions
    46  
    47  * [`file`](./file.html) also reads the contents of a given file,
    48    but interprets the data as UTF-8 text and returns the result directly
    49    as a string, without any further encoding.
    50  * [`base64decode`](./base64decode.html) can decode a Base64 string representing
    51    bytes in UTF-8, but in practice `base64decode(filebase64(...))` is equivalent
    52    to the shorter expression `file(...)`.