tools

package
v2.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package tools is where some legacy provider functions were dropped

Index

Constants

View Source
const DateTimeFormat = "2006-01-02T15:04:05Z"

DateTimeFormat is the layout used across the provider.

Variables

View Source
var (
	// ErrInvalidType is returned when given value is of invalid type (i.e. different type than requested)
	ErrInvalidType = errors.New("value must be of the specified type")
	// ErrNotFound is returned when value is not present on schema
	ErrNotFound = errors.New("value not found")
	// ErrValueSet is returned when setting property value returned an error
	ErrValueSet = errors.New("setting property value")
	// ErrEmptyKey is returned when setting property value returned an error
	ErrEmptyKey = errors.New("provided key cannot be empty")
	// ErrEmptyPath is returned when path is empty
	ErrEmptyPath = errors.New("path cannot be empty")
)
View Source
var ErrDateFormat = errors.New("unable to parse date")

ErrDateFormat is returned when there is an error parsing a string date

Functions

func AddPrefix

func AddPrefix(str, pre string) string

AddPrefix will add prefix to given string.

func AggregateValidations

func AggregateValidations(funcs ...schema.SchemaValidateDiagFunc) schema.SchemaValidateDiagFunc

AggregateValidations takes any number of schema.SchemaValidateDiagFunc and executes them one by one it returns a diagnostics object containing combined results of each validation function

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to a bool passed as an argument

func ContainsString

func ContainsString(s []string, searchTerm string) bool

ContainsString determines if the searched string appears in the array

func ConvertListOfIntToInt64 added in v2.2.0

func ConvertListOfIntToInt64(ints []interface{}) []int64

ConvertListOfIntToInt64 casts slice of any type into slice of int64

func ConvertToString

func ConvertToString(data interface{}) (res string)

ConvertToString will convert different types to strings.

func DiagWarningf

func DiagWarningf(format string, a ...interface{}) diag.Diagnostics

DiagWarningf creates a diag.Diagnostics with a single Warning level diag.Diagnostic entry

func DiagsWithErrors

func DiagsWithErrors(d diag.Diagnostics, errs ...error) diag.Diagnostics

DiagsWithErrors appends several errors to a diag.Diagnostics

func FieldPrefixSuppress

func FieldPrefixSuppress(prefix string) schema.SchemaDiffSuppressFunc

FieldPrefixSuppress returns schema.SchemaDiffSuppressFunc which verifies whether values are equal disregarding given prefix

func FindStringValues

func FindStringValues(rd ResourceDataFetcher, keys ...string) []string

FindStringValues searches the ResourceData for the list of keys and returns the array of values

if the value does not exist it is skipped if the value cannot be cast to string it is skipped

func Float64Ptr

func Float64Ptr(f float64) *float64

Float64Ptr returns a pointer to a float64 passed as an argument

func GetBoolValue

func GetBoolValue(key string, rd ResourceDataFetcher) (bool, error)

GetBoolValue fetches value with given key from ResourceData object and attempts type cast to bool

if value is not present on provided resource, ErrNotFound is returned if casting is not successful, ErrInvalidType is returned

func GetExactlyOneOf

func GetExactlyOneOf(rd ResourceDataFetcher, keys []string) (foundKey string, value interface{}, err error)

GetExactlyOneOf extracts exactly one value with given keys from ResourceData object if multiple values are present the function returns first one found

func GetFirstNotEmpty

func GetFirstNotEmpty(values ...string) string

GetFirstNotEmpty returns first not empty string

func GetFloat32Value

func GetFloat32Value(key string, rd ResourceDataFetcher) (float32, error)

GetFloat32Value fetches value with given key from ResourceData object and attempts type cast to float64

if value is not present on provided resource, ErrNotFound is returned if casting is not successful, ErrInvalidType is returned

func GetFloat64Value

func GetFloat64Value(key string, rd ResourceDataFetcher) (float64, error)

GetFloat64Value fetches value with given key from ResourceData object and attempts type cast to float64

if value is not present on provided resource, ErrNotFound is returned if casting is not successful, ErrInvalidType is returned

func GetIntID

func GetIntID(str, prefix string) (int, error)

GetIntID is used to get the id out from the string.

func GetIntValue

func GetIntValue(key string, rd ResourceDataFetcher) (int, error)

GetIntValue fetches value with given key from ResourceData object and attempts type cast to int

if value is not present on provided resource, ErrNotFound is returned if casting is not successful, ErrInvalidType is returned

func GetInterfaceArrayValue

func GetInterfaceArrayValue(key string, rd ResourceDataFetcher) ([]interface{}, error)

GetInterfaceArrayValue fetches value with given key from ResourceData object and attempts type cast to []interface{}

if value is not present on provided resource for key, ErrNotFound is returned if casting is not successful, ErrInvalidType is returned

func GetListValue

func GetListValue(key string, rd ResourceDataFetcher) ([]interface{}, error)

GetListValue fetches value with given key from ResourceData object and attempts type cast to []interface{}

if value is not present on provided resource, ErrNotFound is returned if casting is not successful, ErrInvalidType is returned

func GetMd5Sum

func GetMd5Sum(key interface{}) (string, error)

GetMd5Sum calculates md5Sum for any given interface{}. Passing a nil pointer to GetMd5Sum will panic, as they cannot be transmitted by gob.

func GetSHAString

func GetSHAString(rdata string) string

GetSHAString returns a sha1 from the string

func GetSchemaFieldNameFromPath

func GetSchemaFieldNameFromPath(path cty.Path) (string, error)

GetSchemaFieldNameFromPath returns schema field name from given path

if len of path is zero it returns empty string and error

func GetSetValue

func GetSetValue(key string, rd ResourceDataFetcher) (*schema.Set, error)

GetSetValue fetches value with given key from ResourceData object and attempts type cast to *schema.Set

if value is not present on provided resource, ErrNotFound is returned if casting is not successful, ErrInvalidType is returned

func GetStringValue

func GetStringValue(key string, rd ResourceDataFetcher) (string, error)

GetStringValue fetches value with given key from ResourceData object and attempts type cast to string

if value is not present on provided resource for key, ErrNotFound is returned if casting is not successful, ErrInvalidType is returned

func Int64Ptr

func Int64Ptr(i int64) *int64

Int64Ptr returns a pointer to an int64 passed as an argument

func IntPtr

func IntPtr(i int) *int

IntPtr returns a pointer to an integer passed as an argument

func IsNotBlank

func IsNotBlank(i interface{}, _ cty.Path) diag.Diagnostics

IsNotBlank verifies whether given value is not blank and returns error if it is where "blank" means: - nil value - a collection with len == 0 in case the value is a map, array or slice - value equal to zero-value for given type (e.g. empty string)

func MaxDuration

func MaxDuration(x, y time.Duration) time.Duration

MaxDuration returns the larger of x or y.

func ParseDate

func ParseDate(layout, value string) (time.Time, error)

ParseDate is used to parse the date with default layout as DateTimeFormat.

func ResetAttrs

func ResetAttrs(d *schema.ResourceData, attributes ...string) error

ResetAttrs resets (sets to nil) the provided set of attributes

func ResolveKeyStringState

func ResolveKeyStringState(rd ResourceDataFetcher, key, fallbackKey string) (value string, err error)

ResolveKeyStringState fetches value with given key (or fallbackKey) from ResourceData object

func RestoreOldValues

func RestoreOldValues(rd *schema.ResourceData, keys []string) error

RestoreOldValues reverts the value in schema of the given keys

func SetAttrs

func SetAttrs(d *schema.ResourceData, AttributeValues map[string]interface{}) error

SetAttrs allows you to set many attributes of a schema.ResourceData in one call

func SetToStringSlice

func SetToStringSlice(s *schema.Set) []string

SetToStringSlice converts schema.Set to a slice of strings

func StateNetwork

func StateNetwork(i interface{}) string

StateNetwork changes the value of the input before storing it in state

func StringPtr

func StringPtr(s string) *string

StringPtr returns a pointer to a string passed as an argument

func ValidateEmail

func ValidateEmail(val interface{}, _ cty.Path) diag.Diagnostics

ValidateEmail checks if value is a valid email

func ValidateJSON

func ValidateJSON(val interface{}, _ cty.Path) diag.Diagnostics

ValidateJSON checks whether given value is a valid JSON object

func ValidateNetwork

func ValidateNetwork(i interface{}, _ cty.Path) diag.Diagnostics

ValidateNetwork defines network validation logic

func ValidateStringInSlice

func ValidateStringInSlice(valid []string) schema.SchemaValidateDiagFunc

ValidateStringInSlice returns schema.SchemaValidateDiagFunc which tests if the value is a string and if it matches given slice of valid strings

Types

type ResourceDataFetcher

type ResourceDataFetcher interface {
	GetOk(string) (interface{}, bool)
}

ResourceDataFetcher ...

Jump to

Keyboard shortcuts

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