Encoding Functions
This section will cover the different encoding functions available in Terraform. You can use them to encode the files created in your own configuration or decode a given file in a specific scheme.
The examples used in the section will be available with the filename 8. encoding-functions.txt
in the GitHub link provided at the start of this chapter.
The base64encode() and base64decode() Functions
These functions can encode a given string in base64
format, decode a base64
encoded string, and return the original string.
Here is an example:
$ base64encode("This is a string")
> "VGhpcyBpcyBhIHN0cmluZw=="
$ base64decode("VGhpcyBpcyBhIHN0cmluZw==")
> "This is a string"
The base64gzip() Function
This function compresses a string with gzip
and then encodes it with base64
encoding.
Here is an example:
$ base64gzip("This is a string")
> "H4sIAAAAAAAA/wrJyCxWyCxWSFQoLinKzEsHAAAA...