2018-05-13 19:40:57 +02:00
|
|
|
---
|
2021-11-23 00:57:25 +01:00
|
|
|
layout: "language"
|
|
|
|
page_title: "base64decode - Functions - Configuration Language"
|
|
|
|
sidebar_current: "docs-funcs-encoding-base64decode"
|
|
|
|
description: |-
|
|
|
|
The base64decode function decodes a string containing a base64 sequence.
|
2018-05-13 19:40:57 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
# `base64decode` Function
|
|
|
|
|
|
|
|
`base64decode` takes a string containing a Base64 character sequence and
|
|
|
|
returns the original 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 also interpret the resulting bytes as
|
|
|
|
UTF-8. If the bytes after Base64 decoding are _not_ valid UTF-8, this function
|
|
|
|
produces an error.
|
|
|
|
|
|
|
|
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, which avoids the need to encode or decode it directly in
|
|
|
|
most cases. Various other functions with names containing "base64" can generate
|
|
|
|
or manipulate Base64 data directly.
|
|
|
|
|
2020-07-03 14:01:40 +02:00
|
|
|
`base64decode` is, in effect, a shorthand for calling
|
2021-11-23 00:57:25 +01:00
|
|
|
[`textdecodebase64`](./textdecodebase64.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
|
|
|
|
|
|
|
|
```
|
|
|
|
> base64decode("SGVsbG8gV29ybGQ=")
|
|
|
|
Hello World
|
|
|
|
```
|
|
|
|
|
|
|
|
## Related Functions
|
|
|
|
|
2021-11-23 00:57:25 +01:00
|
|
|
* [`base64encode`](./base64encode.html) performs the opposite operation,
|
2018-05-13 19:40:57 +02:00
|
|
|
encoding the UTF-8 bytes for a string as Base64.
|
2021-11-23 00:57:25 +01:00
|
|
|
* [`textdecodebase64`](./textdecodebase64.html) is a more general function that
|
2020-07-03 14:01:40 +02:00
|
|
|
supports character encodings other than UTF-8.
|
2021-11-23 00:57:25 +01:00
|
|
|
* [`base64gzip`](./base64gzip.html) applies gzip compression to a string
|
2018-05-13 19:40:57 +02:00
|
|
|
and returns the result with Base64 encoding.
|
2021-11-23 00:57:25 +01:00
|
|
|
* [`filebase64`](./filebase64.html) reads a file from the local filesystem
|
2018-05-13 19:40:57 +02:00
|
|
|
and returns its raw bytes with Base64 encoding.
|