github.com/hugorut/terraform@v1.1.3/website/docs/language/functions/base64encode.mdx (about)

     1  ---
     2  page_title: base64encode - Functions - Configuration Language
     3  description: The base64encode function applies Base64 encoding to a string.
     4  ---
     5  
     6  # `base64encode` Function
     7  
     8  `base64encode` applies Base64 encoding to a string.
     9  
    10  Terraform uses the "standard" Base64 alphabet as defined in
    11  [RFC 4648 section 4](https://tools.ietf.org/html/rfc4648#section-4).
    12  
    13  Strings in the Terraform language are sequences of unicode characters rather
    14  than bytes, so this function will first encode the characters from the string
    15  as UTF-8, and then apply Base64 encoding to the result.
    16  
    17  The Terraform language applies Unicode normalization to all strings, and so
    18  passing a string through `base64decode` and then `base64encode` may not yield
    19  the original result exactly.
    20  
    21  While we do not recommend manipulating large, raw binary data in the Terraform
    22  language, Base64 encoding is the standard way to represent arbitrary byte
    23  sequences, and so resource types that accept or return binary data will use
    24  Base64 themselves, and so this function exists primarily to allow string
    25  data to be easily provided to resource types that expect Base64 bytes.
    26  
    27  `base64encode` is, in effect, a shorthand for calling
    28  [`textencodebase64`](/language/functions/textencodebase64) with the encoding name set to
    29  `UTF-8`.
    30  
    31  ## Examples
    32  
    33  ```
    34  > base64encode("Hello World")
    35  SGVsbG8gV29ybGQ=
    36  ```
    37  
    38  ## Related Functions
    39  
    40  * [`base64decode`](/language/functions/base64decode) performs the opposite operation,
    41    decoding Base64 data and interpreting it as a UTF-8 string.
    42  * [`textencodebase64`](/language/functions/textencodebase64) is a more general function that
    43    supports character encodings other than UTF-8.
    44  * [`base64gzip`](/language/functions/base64gzip) applies gzip compression to a string
    45    and returns the result with Base64 encoding all in one operation.
    46  * [`filebase64`](/language/functions/filebase64) reads a file from the local filesystem
    47    and returns its raw bytes with Base64 encoding, without creating an
    48    intermediate Unicode string.