Skip to main content
base64decode(str) decodes a standard base64-encoded string and returns the original UTF-8 string.

Signature

base64decode(str string) string

Example

Decode a base64-encoded secret stored in an environment variable before passing it to a command:
computed "registry_password" {
  description = "Decoded container registry password"
  expression  = base64decode(env("REGISTRY_PASSWORD_B64", ""))
}

task "login" {
  description = "Authenticate with the container registry"
  commands    = ["docker login registry.example.com -u ci --password-stdin <<< '${computed.registry_password}'"]
}
The secret is stored encoded in the CI environment and decoded at run time.

Notes

  • The input must be valid standard base64. URL-safe base64 (with - and _) is not supported directly. Use replace to convert if needed.
  • The decoded value is interpreted as a UTF-8 string. Binary content may not round-trip cleanly.
  • For the reverse operation, use base64encode.