Help us shape the future of Go! Take the 2026 Go Developer Survey

flatteners

package
v1.12.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(in *bool) basetypes.BoolValue

func BoolPtrDefault added in v1.12.6

func BoolPtrDefault(in *bool) basetypes.BoolValue

BoolPtrDefault returns false (not null) when in is nil, otherwise *in. Use for Computed bool attributes that must hold a known value in state — a null value is skipped by UseStateForUnknown and re-plans as "known after apply" forever.

func Float64

func Float64(in float64) basetypes.Float64Value

Int64 accepts a `int64` and returns a `basetypes.Int64Value`. The return type automatically handles `Int64Null` should the integer be 0.

Removes the need for the following code when saving to state.

if response.MyField == "" {
    state.MyField = types.Int64Value(response.MyField)
} else {
    state.MyField = types.Int64Null()
}

Not recommended if you care about returning an empty string for the state.

nolint: contextcheck

func Int32

func Int32(in int) basetypes.Int32Value

func Int32Ptr

func Int32Ptr(in *int) basetypes.Int32Value

func Int64

func Int64(in int64) basetypes.Int64Value

Int64 accepts a `int64` and returns a `basetypes.Int64Value`. The return type automatically handles `Int64Null` should the integer be 0.

Removes the need for the following code when saving to state.

if response.MyField == "" {
    state.MyField = types.Int64Value(response.MyField)
} else {
    state.MyField = types.Int64Null()
}

Not recommended if you care about returning an empty string for the state.

nolint: contextcheck

func Int64Ptr

func Int64Ptr(in *int) basetypes.Int64Value

func Int64PtrDefault added in v1.11.0

func Int64PtrDefault(in *int) basetypes.Int64Value

func IsEmptyObject added in v1.11.0

func IsEmptyObject(v any) bool

IsEmptyObject reports whether v marshals to "{}". SDK structs use omitempty on every field, so a struct populated entirely with zero-values (what you get when the API returns "{}") marshals back to exactly two bytes. Use this in convertXxxFromAPI alongside the nil check:

if cfg == nil || flatteners.IsEmptyObject(cfg) {
    return nullObj, nil
}

func JSONInterfaceToString added in v1.11.0

func JSONInterfaceToString(v interface{}) types.String

func JSONInterfaceToStringDefault added in v1.11.0

func JSONInterfaceToStringDefault(v interface{}) types.String

func ListOfStringToTerraformList

func ListOfStringToTerraformList(l []string) (types.List, diag.Diagnostics)

ListOfStringToTerraformList converts l to a Terraform list: a nil slice (the field genuinely absent/null) becomes null, while any non-nil slice — including an empty one — becomes a known list ([] for zero-length). Preserving that distinction matters for Optional (and Optional+Computed) attributes: an explicitly-configured empty list plans as a known, empty value, so collapsing the read-back value to null would disagree with that known plan and fail Terraform's post-apply consistency check ("Provider produced inconsistent result after apply").

func MapStringString added in v1.11.0

func MapStringString(ctx context.Context, m map[string]string) (types.Map, diag.Diagnostics)

MapStringString converts a map[string]string to types.Map. Returns null if the map is nil or empty.

func MapStringStringOrEmpty added in v1.11.0

func MapStringStringOrEmpty(ctx context.Context, m map[string]string) (types.Map, diag.Diagnostics)

MapStringStringOrEmpty converts a map[string]string to types.Map. Returns an empty (non-null) map when nil or empty, so UseStateForUnknown has a concrete value to carry forward on subsequent plans.

func String

func String(in string) basetypes.StringValue

String accepts a `string` and returns a `basetypes.StringValue`. The return type automatically handles `StringNull` should the string be empty.

Removes the need for the following code when saving to state.

if response.MyField == "" {
    state.MyField = types.StringValue(response.MyField)
} else {
    state.MyField = types.StringNull()
}

Not recommended if you care about returning an empty string for the state.

nolint: contextcheck

func StringPtr

func StringPtr(in *string) basetypes.StringValue

func StringPtrDefault added in v1.11.0

func StringPtrDefault(in *string) basetypes.StringValue

func StringPtrDefaultNull added in v1.11.0

func StringPtrDefaultNull(in *string) basetypes.StringValue

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL