Back to Packer

`textencodebase64` Function

website/content/docs/templates/hcl_templates/functions/encoding/textencodebase64.mdx

1.15.31.4 KB
Original Source

⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

[!IMPORTANT]
Documentation Update: Product documentation previously located in /website has moved to the hashicorp/web-unified-docs repository, where all product documentation is now centralized. Please make contributions directly to web-unified-docs, since changes to /website in this repository will not appear on developer.hashicorp.com. ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

textencodebase64 Function

Encodes the input string to the destination encoding. The output is base64-encoded to account for HCL's string encoding limitations: they must be UTF-8, NFC-normalised.

Packer uses the standard base64 alphabet as defined in RFC 4648 section 4.

The encoding_name argument must contain one of the encoding names or aliases recorded in the IANA character encoding registry.

Examples

shell-session
# Usage: textencodebase64(input_string, encoding_name)
> textencodebase64("Hello World", "UTF-16LE")
SABlAGwAbABvACAAVwBvAHIAbABkAA==
  • base64encode performs the opposite operation, encoding the UTF-8 bytes for a string as Base64.