• HashiCorp Developer

  • HashiCorp Cloud Platform
  • Terraform
  • Packer
  • Consul
  • Vault
  • Boundary
  • Nomad
  • Waypoint
  • Vagrant
Terraform
  • Install
  • Tutorials
    • About the Docs
    • Configuration Language
    • Terraform CLI
    • Terraform Cloud
    • Terraform Enterprise
    • CDK for Terraform
    • Provider Use
    • Plugin Development
    • Registry Publishing
    • Integration Program
  • Registry(opens in new tab)
  • Try Cloud(opens in new tab)
  • Sign up
Terraform Home

Configuration Language

Skip to main content
  • Configuration Language
  • Data Sources
    • Overview
      • abspath
      • dirname
      • pathexpand
      • basename
      • file
      • fileexists
      • fileset
      • filebase64
      • templatefile
  • Upgrading to Terraform v1.3
  • v1.x Compatibility Promises

  • Terraform Internals

  • Resources

  • Tutorial Library
  • Certifications
  • Community Forum
    (opens in new tab)
  • Support
    (opens in new tab)
  • GitHub
    (opens in new tab)
  • Terraform Registry
    (opens in new tab)
  1. Developer
  2. Terraform
  3. Configuration Language
  4. Functions
  5. filebase64
  • Terraform
  • v1.2.x
  • v1.1 and earlier

ยปfilebase64 Function

filebase64 reads the contents of a file at the given path and returns them as a base64-encoded string.

filebase64(path)

The result is a Base64 representation of the raw bytes in the given file. Strings in the Terraform language are sequences of Unicode characters, so Base64 is the standard way to represent raw binary data that cannot be interpreted as Unicode characters. Resource types that operate on binary data will accept this data encoded in Base64, thus avoiding the need to decode the result of this function.

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

This function can be used only with functions that already exist as static files on disk at the beginning of a Terraform run. Language functions do not participate in the dependency graph, so this function cannot be used with files that are generated dynamically during a Terraform operation.

Examples

> filebase64("${path.module}/hello.txt")
SGVsbG8gV29ybGQ=

Related Functions

  • file also reads the contents of a given file, but interprets the data as UTF-8 text and returns the result directly as a string, without any further encoding.
  • base64decode can decode a Base64 string representing bytes in UTF-8, but in practice base64decode(filebase64(...)) is equivalent to the shorter expression file(...).
Edit this page on GitHub

On this page

  1. filebase64 Function
  2. Examples
  3. Related Functions
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)