util

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddInvalidProviderConfigurationValue added in v1.0.4

func AddInvalidProviderConfigurationValue(diagnostics *diag.Diagnostics, attributeName, attributeNamePretty, attributeInput string, attributeExpectedValues []string)

func AddMissingRequiredProviderConfigurationValue

func AddMissingRequiredProviderConfigurationValue(diagnostics *diag.Diagnostics, attributeName, attributeNamePretty, attributeEnvVar string)

func AddUnexpectedDataSourceConfigurationTypeError

func AddUnexpectedDataSourceConfigurationTypeError(diagnostics *diag.Diagnostics, expectedType, receivedType any)

func AddUnexpectedEphemeralResourceConfigurationTypeError

func AddUnexpectedEphemeralResourceConfigurationTypeError(diagnostics *diag.Diagnostics, expectedType, receivedType any)

func AddUnexpectedResourceConfigurationTypeError

func AddUnexpectedResourceConfigurationTypeError(diagnostics *diag.Diagnostics, expectedType, receivedType any)

func ApplyBoolEnvVar added in v1.0.4

func ApplyBoolEnvVar(ctx context.Context, envVar string, dest *types.Bool, diags *diag.Diagnostics)

ApplyBoolEnvVar reads envVar from the environment and, if non-empty, parses it as bool and overwrites dest. A parse error is appended to diags.

func ApplyInt32EnvVar added in v1.0.4

func ApplyInt32EnvVar(ctx context.Context, envVar string, dest *types.Int32, diags *diag.Diagnostics)

ApplyInt32EnvVar reads envVar from the environment and, if non-empty, parses it as int32 and overwrites dest. A parse error is appended to diags.

func ApplyStringEnvVar added in v1.0.4

func ApplyStringEnvVar(ctx context.Context, envVar string, dest *types.String)

ApplyStringEnvVar reads envVar from the environment and, if non-empty, overwrites dest with the value. A debug log line is emitted on each successful overwrite.

func AttributeMapFromObject

func AttributeMapFromObject(m ModelWithAttributes) (map[string]attr.Type, error)

<summary> Helper function to convert a model to a map of attribute types. Used when converting back to a types.Object </summary> <param name="m">Model to convert, must implement the ModelWithSchema interface</param> <returns>Map of attribute types</returns>

func ConvertBaseStringArrayToPrimitiveStringArray

func ConvertBaseStringArrayToPrimitiveStringArray(v []types.String) []string

<summary> Helper function to convert array of terraform strings to array of golang primitive strings Deprecated: Remove after we fully move to types.List </summary> <param name="v">Array of terraform stringsArray of golang primitive strings</param> <returns>Array of golang primitive strings</returns>

func ConvertPrimitiveInterfaceArrayToStringList

func ConvertPrimitiveInterfaceArrayToStringList(ctx context.Context, diagnostics *diag.Diagnostics, v []any) (types.List, string)

<summary> Helper function to convert array of golang primitive interface to native terraform list of strings </summary> <param name="v">Array of golang primitive interface</param> <returns>Terraform list of strings</returns>

func FindElement

func FindElement[T any](slice []T, criteria any) (T, bool)

FindElement searches for an element in a slice and returns it if found, along with a boolean indicating if it was found. The criteria argument can be either a value to compare directly with elements in the slice, or a map[string]any of key-value pairs to match against the fields of a struct element.

func FormatAPIError added in v1.0.4

func FormatAPIError(err error) string

FormatAPIError returns a human-readable error message that includes per-field validation details when the underlying error is a structured CortexCloudAPIError. For non-API errors (or API errors with no details), it returns err.Error() unchanged.

This bridges the SDK's structured error type to provider diagnostics so HTTP 422 ValidateError responses surface their per-field messages instead of being swallowed as a single opaque "Validation Failed" line.

func GetEnvironmentVariable

func GetEnvironmentVariable(name string, reciever any) error

GetEnvironmentVariable retrieves the string value of the specified environment variable, converts it to the type of the reciever argument, and assigns address of the converted value to reciever.

If the environment variable is not set, is set to an empty value, or is unable to be converted into the reciever type, the function will exit without modifying reciever and return an error.

func Int32PointerIsNilOrNegative

func Int32PointerIsNilOrNegative(value *int32) bool

func ListToStringSlice

func ListToStringSlice(ctx context.Context, l *basetypes.ListValue, response *[]string) diag.Diagnostics

Converts basetypes.ListValue to string slice and populates it in response

func ObjectListToTypedArray

func ObjectListToTypedArray[objTyp any](ctx context.Context, diagnostics *diag.Diagnostics, v types.List) []objTyp

<summary> Helper function to convert a native terraform list of objects to a golang slice of the specified type Use TypedArrayToObjectList to go the other way. </summary> <param name="ctx">context</param> <param name="diagnostics">Any issues will be appended to these diagnostics</param> <param name="v">List of object in the native terraform types.List wrapper</param> <returns>Array of the specified type</returns>

func ObjectSetToTypedArray

func ObjectSetToTypedArray[objTyp any](ctx context.Context, diagnostics *diag.Diagnostics, v types.Set) []objTyp

<summary> Helper function to convert a native terraform list of objects to a golang slice of the specified type Use TypedArrayToObjectSet to go the other way. </summary> <param name="ctx">context</param> <param name="diagnostics">Any issues will be appended to these diagnostics</param> <param name="v">Set of object in the native terraform types.Set wrapper</param> <returns>Array of the specified type</returns>

func ObjectValueToTypedObject

func ObjectValueToTypedObject[objTyp any](ctx context.Context, diagnostics *diag.Diagnostics, v types.Object) objTyp

<summary> Helper function to convert a native terraform object to a golang object of the specified type. Use TypedObjectToObjectValue to go the other way. </summary> <param name="ctx">context</param> <param name="diagnostics">Any issues will be appended to these diagnostics</param> <param name="v">Object in the native terraform types.Object wrapper</param> <returns>Object of the specified type</returns>

func PanicHandler

func PanicHandler(diagnostics *diag.Diagnostics)

PanicHandler is a global panic handler to catch all unexpected errors to prevent the provider from crashing.

The crash stack is written into a local text file.

func SliceSharesOneOrMoreElements

func SliceSharesOneOrMoreElements(s1 []string, s2 []string) bool

Returns true if s1 shares any elements with s2

func StringArrayToStringList

func StringArrayToStringList(ctx context.Context, diagnostics *diag.Diagnostics, v []string) types.List

<summary> Helper function to convert a golang slice of string to a native terraform list of strings. Use StringListToStringArray to go the other way. </summary> <param name="diagnostics">Any issues will be appended to these diagnostics</param> <param name="v">Slice of strings</param> <returns>types.List</returns>

func StringArrayToStringSet

func StringArrayToStringSet(ctx context.Context, diagnostics *diag.Diagnostics, v []string) types.Set

<summary> Helper function to convert a golang slice of string to a native terraform set of strings. Use StringSetToStringArray to go the other way. </summary> <param name="diagnostics">Any issues will be appended to these diagnostics</param> <param name="v">Slice of strings</param> <returns>types.Set</returns>

func StringListToStringArray

func StringListToStringArray(ctx context.Context, diagnostics *diag.Diagnostics, v types.List) []string

<summary> Helper function to convert a terraform list of terraform strings to array of golang primitive strings. Use StringArrayToStringList to go the other way. </summary> <param name="v">List of terraform strings</param> <returns>Array of golang primitive strings</returns>

func StringPointerIsNilOrEmpty

func StringPointerIsNilOrEmpty(value *string) bool

func StringSetToStringArray

func StringSetToStringArray(ctx context.Context, diagnostics *diag.Diagnostics, v types.Set) []string

<summary> Helper function to convert a terraform set of terraform strings to array of golang primitive strings. Use StringArrayToStringSet to go the other way. </summary> <param name="v">Set of terraform strings</param> <returns>Array of golang primitive strings</returns>

func StringToInt

func StringToInt(str string) (int, error)

func StringToTypeBool

func StringToTypeBool(from string) types.Bool

<summary> Helper function to convert string to terraform boolean value </summary> <param name="from">Boolean value in string</param> <returns>Boolean value in terraform types.Bool</returns>

func TypeBoolToString

func TypeBoolToString(from types.Bool) string

<summary> Helper function to convert terraform bool value to string </summary> <param name="from">Boolean value in terraform bool</param> <returns>Boolean value in string</returns>

func TypedArrayToObjectList

func TypedArrayToObjectList[objTyp ModelWithAttributes](ctx context.Context, diagnostics *diag.Diagnostics, v []objTyp) types.List

<summary> Helper function to convert a golang slice to a native terraform list of objects. Use ObjectListToTypedArray to go the other way. </summary> <param name="diagnostics">Any issues will be appended to these diagnostics</param> <param name="v">Slice of objects</param> <returns>types.List</returns>

func TypedArrayToObjectSet

func TypedArrayToObjectSet[objTyp ModelWithAttributes](ctx context.Context, diagnostics *diag.Diagnostics, v []objTyp) types.Set

<summary> Helper function to convert a golang slice to a native terraform list of objects. Use ObjectSetToTypedArray to go the other way. </summary> <param name="diagnostics">Any issues will be appended to these diagnostics</param> <param name="v">Slice of objects</param> <returns>types.Set</returns>

func TypedObjectToObjectValue

func TypedObjectToObjectValue(ctx context.Context, diagnostics *diag.Diagnostics, v ModelWithAttributes) types.Object

<summary> Helper function to convert a golang object to a native terraform object. Use ObjectValueToTypedObject to go the other way. </summary> <param name="ctx">"context</param> <param name="diagnostics">Any issues will be appended to these diagnostics</param> <param name="v">Object of the specified type</param> <param name="s">Schema map of the object</param> <returns>Object in the native terraform types.Object wrapper</returns>

Types

type ModelWithAttributes

type ModelWithAttributes interface {
	GetAttributes() map[string]schema.Attribute // workaround because NestedAttributeObject and SingleNestedAttribute do not share a base type
}

Jump to

Keyboard shortcuts

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