Skip to content

Support Base64 encoding of raw MD5 digest bytes #39436

Open

Description

@DJAlPee

Terraform Version

Terraform v1.16.6
on darwin_arm64

Use Cases

AWS WAF byte match rules can apply an MD5 text transformation to a request component before comparing it with SearchString. Writing such a rule requires the comparison value to be the Base64 encoding of the raw 16-byte MD5 digest.

Terraform's md5 function returns a hexadecimal string. base64encode(md5(value)) encodes the ASCII hexadecimal representation, not the raw digest bytes. The existing base64sha256 and base64sha512 functions provide the required behavior for their respective algorithms, but there is no MD5 equivalent or general conversion function.

This differs from converting between two provider arguments. The value is derived from arbitrary input and must match a transformation performed by the remote service.

Attempted Solutions

The closest expression using built-in functions is:

base64encode(md5(var.value))

This Base64-encodes the hexadecimal digest rather than the raw digest bytes.

A shell workaround is:

printf '%s' "$INPUT" | openssl dgst -md5 -binary | openssl base64 -A

Using this from Terraform requires an external data source, provider-defined function, or another out-of-process step. This adds dependencies and execution overhead for a deterministic transformation.

Proposal

Provide a built-in way to return the Base64 encoding of raw MD5 digest bytes.

One option is a base64md5 function, consistent with base64sha256 and base64sha512:

base64md5("hello world")

Alternatively, a general function that directly transcodes hexadecimal data to Base64 would allow composition without introducing binary strings:

base64_from_hex(md5("hello world"))

The exact API name is open for discussion. In either form, the result would be:

XrY7u+Ae7tCTyyK7j1rNww==

References

Activity

  1. crw commented on Oct 22, 2026

    @crw
    Contributor

    Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again!

  2. crw commented on Oct 22, 2026

    @crw
    Contributor

    You might also file this in the AWS provider repo, and they could add a provider function to solve this problem. https://github.com/hashicorp/terraform-provider-aws/issues/new/choose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions