Skip to content

tm_base64gzip Function

tm_base64gzip compresses a string with gzip and then encodes the result in Base64 encoding.

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

Strings in the Terraform language are sequences of unicode characters rather than bytes, so this function will first encode the characters from the string as UTF-8, then apply gzip compression, and then finally apply Base64 encoding.

While we do not recommend manipulating large, raw binary data in the Terraform language, this function can be used to compress reasonably sized text strings generated within the Terraform language. For example, the result of this function can be used to create a compressed object in Amazon S3 as part of an S3 website.

  • tm_base64encode applies Base64 encoding without gzip compression.
  • tm_filebase64 reads a file from the local filesystem and returns its raw bytes with Base64 encoding.