From 5bfd778aa732cf0855ef1d01c498f073a6dfb4b0 Mon Sep 17 00:00:00 2001 From: karthik P Date: Thu, 24 Apr 2025 23:05:04 +0530 Subject: [PATCH] adding docs for filebase64 function --- .../functions/file/filebase64.mdx | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 website/content/docs/templates/hcl_templates/functions/file/filebase64.mdx diff --git a/website/content/docs/templates/hcl_templates/functions/file/filebase64.mdx b/website/content/docs/templates/hcl_templates/functions/file/filebase64.mdx new file mode 100644 index 000000000..1b60fcc7f --- /dev/null +++ b/website/content/docs/templates/hcl_templates/functions/file/filebase64.mdx @@ -0,0 +1,46 @@ +--- +page_title: filebase64 - Functions - Configuration Language +description: |- + The filebase64 function reads the contents of the file at the given path and + returns them as a base64-encoded string. +--- + +# `filebase64` Function + +`filebase64` reads the contents of a file at the given path and returns them as +a base64-encoded string. + +```hcl +filebase64(path) +``` + +The result is a Base64 representation of the raw bytes in the given file. +Strings in the Packer language are sequences of Unicode characters, so +Base64 is the standard way to represent raw binary data that cannot be +interpreted as Unicode characters. Resource types that operate on binary +data will accept this data encoded in Base64, thus avoiding the need to +decode the result of this function. + +Packer uses the "standard" Base64 alphabet as defined in +[RFC 4648 section 4](https://tools.ietf.org/html/rfc4648#section-4). + +This function can be used only with functions that already exist as static +files on disk at the beginning of a Packer run. Language functions do not +participate in the dependency graph, so this function cannot be used with +files that are generated dynamically during a Packer operation. + +## Examples + +``` +> filebase64("${path.module}/hello.txt") +SGVsbG8gV29ybGQ= +``` + +## Related Functions + +* [`file`](/packer/docs/templates/hcl_templates/functions/file/file) also reads the contents of a given file, + but interprets the data as UTF-8 text and returns the result directly + as a string, without any further encoding. +* [`base64decode`](/packer/docs/templates/hcl_templates/functions/encoding/base64decode) can decode a Base64 string representing + bytes in UTF-8, but in practice `base64decode(filebase64(...))` is equivalent + to the shorter expression `file(...)`.