2020-07-03 14:01:40 +02:00
|
|
|
---
|
2021-12-15 03:41:17 +01:00
|
|
|
page_title: textencodebase64 - Functions - Configuration Language
|
|
|
|
description: >-
|
|
|
|
The textencodebase64 function encodes the unicode characters in a given string
|
|
|
|
using a
|
|
|
|
|
2020-12-02 22:51:29 +01:00
|
|
|
specified character encoding, returning the result base64 encoded.
|
2020-07-03 14:01:40 +02:00
|
|
|
---
|
|
|
|
|
2020-10-21 19:56:56 +02:00
|
|
|
# `textencodebase64` Function
|
2020-07-03 14:01:40 +02:00
|
|
|
|
|
|
|
-> **Note:** This function is supported only in Terraform v0.14 and later.
|
|
|
|
|
2020-10-21 19:56:56 +02:00
|
|
|
`textencodebase64` encodes the unicode characters in a given string using a
|
2020-07-03 14:01:40 +02:00
|
|
|
specified character encoding, returning the result base64 encoded because
|
|
|
|
Terraform language strings are always sequences of unicode characters.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
substr(string, encoding_name)
|
|
|
|
```
|
|
|
|
|
|
|
|
Terraform 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).
|
|
|
|
Terraform supports only a subset of the registered encodings, and the encoding
|
|
|
|
support may vary between Terraform versions. In particular Terraform supports
|
|
|
|
`UTF-16LE`, which is the native character encoding for the Windows API and
|
|
|
|
therefore sometimes expected by Windows-originated software such as PowerShell.
|
|
|
|
|
|
|
|
Terraform also accepts the encoding name `UTF-8`, which will produce the same
|
2021-12-15 03:41:17 +01:00
|
|
|
result as [`base64encode`](/language/functions/base64encode).
|
2020-07-03 14:01:40 +02:00
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```
|
2020-10-21 19:56:56 +02:00
|
|
|
> textencodebase64("Hello World", "UTF-16LE")
|
2020-07-03 14:01:40 +02:00
|
|
|
SABlAGwAbABvACAAVwBvAHIAbABkAA==
|
|
|
|
```
|
|
|
|
|
|
|
|
## Related Functions
|
|
|
|
|
2021-12-15 03:41:17 +01:00
|
|
|
* [`textdecodebase64`](/language/functions/textdecodebase64) performs the opposite operation,
|
2020-07-03 14:01:40 +02:00
|
|
|
decoding Base64 data and interpreting it as a particular character encoding.
|
2021-12-15 03:41:17 +01:00
|
|
|
* [`base64encode`](/language/functions/base64encode) applies Base64 encoding of the UTF-8
|
2020-07-03 14:01:40 +02:00
|
|
|
encoding of a string.
|
2021-12-15 03:41:17 +01:00
|
|
|
* [`filebase64`](/language/functions/filebase64) reads a file from the local filesystem
|
2020-07-03 14:01:40 +02:00
|
|
|
and returns its raw bytes with Base64 encoding, without creating an
|
|
|
|
intermediate Unicode string.
|