2018-05-13 19:40:57 +02:00
|
|
|
---
|
|
|
|
layout: "functions"
|
2018-12-20 05:35:11 +01:00
|
|
|
page_title: "base64encode - Functions - Configuration Language"
|
2018-05-13 19:40:57 +02:00
|
|
|
sidebar_current: "docs-funcs-encoding-base64encode"
|
|
|
|
description: |-
|
|
|
|
The base64encode function applies Base64 encoding to a string.
|
|
|
|
---
|
|
|
|
|
|
|
|
# `base64encode` Function
|
|
|
|
|
2019-01-17 01:33:57 +01:00
|
|
|
-> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and
|
|
|
|
earlier, see
|
|
|
|
[0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html).
|
|
|
|
|
2018-05-13 19:40:57 +02:00
|
|
|
`base64encode` applies Base64 encoding to a string.
|
|
|
|
|
|
|
|
Terraform uses the "standard" Base64 alphabet as defined in
|
|
|
|
[RFC 4648 section 4](https://tools.ietf.org/html/rfc4648#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, and then apply Base64 encoding to the result.
|
|
|
|
|
|
|
|
The Terraform language applies Unicode normalization to all strings, and so
|
|
|
|
passing a string through `base64decode` and then `base64encode` may not yield
|
|
|
|
the original result exactly.
|
|
|
|
|
|
|
|
While we do not recommend manipulating large, raw binary data in the Terraform
|
|
|
|
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, and so this function exists primarily to allow string
|
|
|
|
data to be easily provided to resource types that expect Base64 bytes.
|
|
|
|
|
2020-07-03 14:01:40 +02:00
|
|
|
`base64encode` is, in effect, a shorthand for calling
|
2020-10-21 19:56:56 +02:00
|
|
|
[`textencodebase64`](./textencodebase64.html) with the encoding name set to
|
2020-07-03 14:01:40 +02:00
|
|
|
`UTF-8`.
|
|
|
|
|
2018-05-13 19:40:57 +02:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
```
|
|
|
|
> base64encode("Hello World")
|
|
|
|
SGVsbG8gV29ybGQ=
|
|
|
|
```
|
|
|
|
|
|
|
|
## Related Functions
|
|
|
|
|
|
|
|
* [`base64decode`](./base64decode.html) performs the opposite operation,
|
|
|
|
decoding Base64 data and interpreting it as a UTF-8 string.
|
2020-10-21 19:56:56 +02:00
|
|
|
* [`textencodebase64`](./textencodebase64.html) is a more general function that
|
2020-07-03 14:01:40 +02:00
|
|
|
supports character encodings other than UTF-8.
|
2018-05-13 19:40:57 +02:00
|
|
|
* [`base64gzip`](./base64gzip.html) applies gzip compression to a string
|
|
|
|
and returns the result with Base64 encoding all in one operation.
|
|
|
|
* [`filebase64`](./filebase64.html) reads a file from the local filesystem
|
|
|
|
and returns its raw bytes with Base64 encoding, without creating an
|
|
|
|
intermediate Unicode string.
|