Files
opentf/website/docs/language/functions/textencodebase64.mdx
Oleksandr Levchenkov adcdec9525 Update textencodebase64 and textdecodebase64 documentation (#1634)
Signed-off-by: Alexis Saettler <alexis@saettler.org>
Co-authored-by: Alexis Saettler <alexis@saettler.org>
2024-05-09 06:41:23 -04:00

50 lines
1.9 KiB
Plaintext

---
sidebar_label: textencodebase64
description: >-
The textencodebase64 function encodes the unicode characters in a given string
using a
specified character encoding, returning the result base64 encoded.
---
# `textencodebase64` Function
`textencodebase64` encodes the unicode characters in a given string using a
specified character encoding, returning the result base64 encoded because
OpenTofu language strings are always sequences of unicode characters.
```hcl
textencodebase64(string, encoding_name)
```
OpenTofu uses the "standard" Base64 alphabet as defined in
[RFC 4648 section 4](https://tools.ietf.org/html/rfc4648#section-4).
The `encoding_name` argument must contain one of the encoding names or aliases
recorded in
[the IANA character encoding registry](https://www.iana.org/assignments/character-sets/character-sets.xhtml).
OpenTofu supports only a subset of the registered encodings, and the encoding
support may vary between OpenTofu versions. In particular OpenTofu supports
`UTF-16LE`, which is the native character encoding for the Windows API and
therefore sometimes expected by Windows-originated software such as PowerShell.
OpenTofu also accepts the encoding name `UTF-8`, which will produce the same
result as [`base64encode`](../../language/functions/base64encode.mdx).
## Examples
```
> textencodebase64("Hello World", "UTF-16LE")
SABlAGwAbABvACAAVwBvAHIAbABkAA==
```
## Related Functions
* [`textdecodebase64`](../../language/functions/textdecodebase64.mdx) performs the opposite operation,
decoding Base64 data and interpreting it as a particular character encoding.
* [`base64encode`](../../language/functions/base64encode.mdx) applies Base64 encoding of the UTF-8
encoding of a string.
* [`filebase64`](../../language/functions/filebase64.mdx) reads a file from the local filesystem
and returns its raw bytes with Base64 encoding, without creating an
intermediate Unicode string.