-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hcl2template: add text(encode|decode)base64 funcs
Compared to Terraform, Packer was lacking a capability to encode/decode strings to/from base64-encoded text encoded with another encoding. This could be problematic in some cases, mainly when working with Windows, as most of the OS uses UTF-16LE as its standard encoding for many operations. Therefore, we take a page from Terraform here, and add those functions to what Packer supports in an HCL2 context.
- Loading branch information
1 parent
92aabc7
commit 3b10a3c
Showing
4 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...te/content/docs/templates/hcl_templates/functions/encoding/textdecodebase64.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
page_title: testdecodebase64 - Functions - Configuration Language | ||
description: The testdecodebase64 function converts a base64 encoded string, whose underlying encoding is the one specified as argument, into a UTF-8 string. | ||
--- | ||
|
||
# `textdecodebase64` Function | ||
|
||
Encodes the input string from a speicified encoding into UTF-8. | ||
The input 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](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). | ||
|
||
## Examples | ||
|
||
```shell-session | ||
# Usage: textencodebase64(input_base64, encoding_name) | ||
> textdecodebase64("SABlAGwAbABvACAAVwBvAHIAbABkAA==", "UTF-16LE") | ||
Hello World | ||
``` | ||
|
||
## Related Functions | ||
|
||
- [`base64encode`](/packer/docs/templates/hcl_templates/functions/encoding/base64encode) performs the opposite operation, | ||
encoding the UTF-8 bytes for a string as Base64. |
28 changes: 28 additions & 0 deletions
28
...te/content/docs/templates/hcl_templates/functions/encoding/textencodebase64.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
page_title: testencodebase64 - Functions - Configuration Language | ||
description: The testencodebase64 function converts a UTF-8 NFC input string to a base64 blob that encodes the target encoding's rendering of the input string. | ||
--- | ||
|
||
# `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](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). | ||
|
||
## Examples | ||
|
||
```shell-session | ||
# Usage: textencodebase64(input_string, encoding_name) | ||
> textencodebase64("Hello World", "UTF-16LE") | ||
SABlAGwAbABvACAAVwBvAHIAbABkAA== | ||
``` | ||
|
||
## Related Functions | ||
|
||
- [`base64encode`](/packer/docs/templates/hcl_templates/functions/encoding/base64encode) performs the opposite operation, | ||
encoding the UTF-8 bytes for a string as Base64. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters