Skip to content

speakeasy-api/terraform-plugin-framework-base64types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

terraform-plugin-framework-base64types

Go Reference

Terraform Plugin Framework custom type implementations for base64 encoded strings (RFC 4648).

Types

Standard (RFC 4648, Section 4)

The Standard type represents a base64 encoded string using the standard alphabet (A-Z, a-z, 0-9, +, /) with = padding. This is the encoding used by Terraform's filebase64() and base64encode() functions, making Standard the appropriate custom type for schema attributes that receive output from these functions.

Use Standard when:

  • The attribute receives output from Terraform's filebase64() function (e.g. binary file content)
  • The attribute receives output from Terraform's base64encode() function
  • The API expects standard base64 encoding

Schema Definition

schema.StringAttribute{
    CustomType:  base64types.StandardType{},
    Required:    true,
    Description: "Binary file content, base64-encoded. Use filebase64() to encode files.",
}

Data Model

type ResourceModel struct {
    FileContent base64types.Standard `tfsdk:"file_content"`
}

Accessing Decoded Bytes

decoded, diags := data.FileContent.ValueBytes()

Creating From Bytes

data.FileContent = base64types.NewStandardValueFromBytes(responseBytes)

URL (RFC 4648, Section 5)

The URL type represents a base64url encoded string using the URL and filename safe alphabet (A-Z, a-z, 0-9, -, _) with = padding. The base64url encoding substitutes - for + and _ for / to avoid characters that have special meaning in URLs and filenames.

Use URL when:

  • The attribute contains base64 data that must be URL-safe (e.g. JWT tokens, URL parameters)
  • The API expects base64url encoding

Schema Definition

schema.StringAttribute{
    CustomType:  base64types.URLType{},
    Required:    true,
    Description: "URL-safe base64-encoded token.",
}

Data Model

type ResourceModel struct {
    Token base64types.URL `tfsdk:"token"`
}

Accessing Decoded Bytes

decoded, diags := data.Token.ValueBytes()

Creating From Bytes

data.Token = base64types.NewURLValueFromBytes(responseBytes)

Validation

Both types automatically validate attribute values and provider-defined function parameter values via the xattr.ValidateableAttribute and function.ValidateableParameter interfaces. Invalid base64 input produces plan-time errors with guidance on how to fix the value.

Semantic Equality

Both types implement basetypes.StringValuableWithSemanticEquals to compare the decoded bytes rather than the encoded strings. This prevents spurious Terraform diffs when two base64 strings decode to the same content.

License

Apache License, Version 2.0

About

base64 Custom Types for Terraform Plugin Framework

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages