Back to Packer

`base64decode` Function

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

1.15.31.7 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. ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

base64decode Function

base64decode takes a string containing a Base64 character sequence and returns the original string.

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

Strings in the Packer language are sequences of unicode characters rather than bytes, so this function will also interpret the resulting bytes as UTF-8. If the bytes after Base64 decoding are not valid UTF-8, this function produces an error.

While we do not recommend manipulating large, raw binary data in the Packer language, Base64 encoding is the standard way to represent arbitrary byte sequences, and so resource types that accept or return binary data will use Base64 themselves, which avoids the need to encode or decode it directly in most cases. Various other functions with names containing "base64" can generate or manipulate Base64 data directly.

Examples

shell-session
> base64decode("SGVsbG8gV29ybGQ=")
Hello World
  • base64encode performs the opposite operation, encoding the UTF-8 bytes for a string as Base64.