utils

package
v0.0.0-...-15940f6 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValidateLabelsDiagFunc = validation.AllDiag(
	validation.MapKeyLenBetween(2, 32),
	validation.MapKeyMatch(labelKeyRegExp, ""),
	validation.MapValueLenBetween(0, 255),
)

Functions

func AsBool

func AsBool(b upcloud.Boolean) types.Bool

func AsSDKv2Diags

func AsSDKv2Diags(diags diag.Diagnostics) sdkv2_diag.Diagnostics

func AsUpCloudBoolean

func AsUpCloudBoolean(b types.Bool) upcloud.Boolean

func EnvKeyExists

func EnvKeyExists(keyPrefix string) bool

func ErrorDiagnosticDetail

func ErrorDiagnosticDetail(err error) string

func ExpandStrings

func ExpandStrings(data interface{}) []string

ExpandStrings expands a terraform list to slice of str

func FilterNetworks

func FilterNetworks(vs []upcloud.Network, fns ...func(upcloud.Network) (bool, error)) ([]upcloud.Network, error)

func FilterZoneIDs

func FilterZoneIDs(vs []upcloud.Zone, f func(upcloud.Zone) bool) []string

func GetClientFromProviderData

func GetClientFromProviderData(providerData any) (client *service.Service, diags diag.Diagnostics)

func GetFirstItem

func GetFirstItem[T any](ctx context.Context, list elementsAser) (*T, diag.Diagnostics)

func HandleResourceError

func HandleResourceError(resourceName string, d *schema.ResourceData, err error) diag.Diagnostics

func IsNotFoundError

func IsNotFoundError(err error) bool

func JoinSchemas

func JoinSchemas(dst map[string]*schema.Schema, s ...map[string]*schema.Schema) map[string]*schema.Schema

func LabelsAttribute

func LabelsAttribute(resource string, additionalPlanModifiers ...planmodifier.Map) schema.Attribute

func LabelsMapToSlice

func LabelsMapToSlice[T any](m map[string]T) []upcloud.Label

func LabelsSchema

func LabelsSchema(resource string) *sdkv2_schema.Schema

func LabelsSliceToMap

func LabelsSliceToMap(s []upcloud.Label) map[string]string

func LabelsSliceToSystemLabelsMap

func LabelsSliceToSystemLabelsMap(s []upcloud.Label) map[string]string

func MarshalID

func MarshalID(components ...string) string

func NilAsEmptyList

func NilAsEmptyList[T any](l []T) []T

func ReadOnlyLabelsAttribute

func ReadOnlyLabelsAttribute(resource string) schema.Attribute

func ReadTestDataFile

func ReadTestDataFile(t *testing.T, name string) string

ReadTestDataFile reads testdata from file to a string. Fails tests with Fatal, if reading the file fails.

func SetAsSliceOfStrings

func SetAsSliceOfStrings(ctx context.Context, set types.Set) ([]string, diag.Diagnostics)

func StorageAddressFormat

func StorageAddressFormat(address string) string

StorageAddressFormat takes the address in any format and extracts the bus type only (ide/scsi/virtio)

func StorageAddressPositionFormat

func StorageAddressPositionFormat(address string) string

StorageAddressPositionFormat takes the address in any format and extracts the bus position only

func SystemLabelsAttribute

func SystemLabelsAttribute(resource string) schema.Attribute

func UnmarshalID

func UnmarshalID(id string, components ...*string) error

func VerifyServerStarted

func VerifyServerStarted(ctx context.Context, startRequest request.StartServerRequest, meta interface{}) error

func VerifyServerStopped

func VerifyServerStopped(ctx context.Context, stopRequest request.StopServerRequest, meta interface{}) error

func WaitForResourceToBeDeleted

func WaitForResourceToBeDeleted(ctx context.Context, svc *service.Service, getDetails func(context.Context, *service.Service, ...string) (map[string]interface{}, error), id ...string) error

func WithRetry

func WithRetry(fn func() (interface{}, error), retries int, delay time.Duration) (interface{}, error)

WithRetry attempts to call the provided function until it has been successfully called or the number of calls exceeds retries delaying the consecutive calls by given delay

Types

This section is empty.

Jump to

Keyboard shortcuts

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