Documentation ¶
Overview ¶
Package tf gathers common logic used for terraform-plugin-sdk resources and data sources.
Index ¶
- Variables
- func AggregateValidations(funcs ...schema.SchemaValidateDiagFunc) schema.SchemaValidateDiagFunc
- func ConvertListOfIntToInt64(ints []interface{}) []int64
- func DiagWarningf(format string, a ...interface{}) diag.Diagnostics
- func DiagsWithErrors(d diag.Diagnostics, errs ...error) diag.Diagnostics
- func DiffSuppressAny(fncs ...schema.SchemaDiffSuppressFunc) schema.SchemaDiffSuppressFunc
- func FieldPrefixSuppress(prefix string) schema.SchemaDiffSuppressFunc
- func FindStringValues(rd ResourceDataFetcher, keys ...string) []string
- func GetBoolValue(key string, rd ResourceDataFetcher) (bool, error)
- func GetExactlyOneOf(rd ResourceDataFetcher, keys []string) (foundKey string, value interface{}, err error)
- func GetFloat32Value(key string, rd ResourceDataFetcher) (float32, error)
- func GetFloat64Value(key string, rd ResourceDataFetcher) (float64, error)
- func GetInt64Value(key string, rd ResourceDataFetcher) (int64, error)
- func GetIntValue(key string, rd ResourceDataFetcher) (int, error)
- func GetIntValueAsInt64(key string, rd ResourceDataFetcher) (int64, error)
- func GetInterfaceArrayValue(key string, rd ResourceDataFetcher) ([]interface{}, error)
- func GetListValue(key string, rd ResourceDataFetcher) ([]interface{}, error)
- func GetMapValue(key string, rd ResourceDataFetcher) (map[string]interface{}, error)
- func GetSchemaFieldNameFromPath(path cty.Path) (string, error)
- func GetSetValue(key string, rd ResourceDataFetcher) (*schema.Set, error)
- func GetStringValue(key string, rd ResourceDataFetcher) (string, error)
- func GetTypedListValue[T any](key string, rd ResourceDataFetcher) ([]T, error)
- func IsNotBlank(i interface{}, _ cty.Path) diag.Diagnostics
- func MaxDuration(x, y time.Duration) time.Duration
- func ResetAttrs(d *schema.ResourceData, attributes ...string) error
- func ResolveKeyStringState(rd ResourceDataFetcher, key, fallbackKey string) (value string, err error)
- func RestoreOldValues(rd *schema.ResourceData, keys []string) error
- func SetAttrs(d *schema.ResourceData, AttributeValues map[string]interface{}) error
- func SetToStringSlice(s *schema.Set) []string
- func StateNetwork(i interface{}) string
- func ValidateEmail(val interface{}, _ cty.Path) diag.Diagnostics
- func ValidateJSON(val interface{}, _ cty.Path) diag.Diagnostics
- func ValidateMapMinimalLength(min int) schema.SchemaValidateDiagFunc
- func ValidateNetwork(i interface{}, _ cty.Path) diag.Diagnostics
- func ValidateRuleFormat(v interface{}, _ cty.Path) diag.Diagnostics
- func ValidateRuleFormatAcceptLatest(v interface{}, _ cty.Path) diag.Diagnostics
- func ValidateStringInSlice(valid []string) schema.SchemaValidateDiagFunc
- type RawConfig
- type RawConfigGetter
- type ResourceChangeFetcher
- type ResourceDataFetcher
Constants ¶
This section is empty.
Variables ¶
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") )
Functions ¶
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 ConvertListOfIntToInt64 ¶
func ConvertListOfIntToInt64(ints []interface{}) []int64
ConvertListOfIntToInt64 casts slice of any type into slice of int64
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 DiffSuppressAny ¶
func DiffSuppressAny(fncs ...schema.SchemaDiffSuppressFunc) schema.SchemaDiffSuppressFunc
DiffSuppressAny aggregates all given schema.SchemaDiffSuppressFunc into one. Aggregated function returns true if any of the functions returns true.
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 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 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 GetInt64Value ¶
func GetInt64Value(key string, rd ResourceDataFetcher) (int64, error)
GetInt64Value fetches value with given key from ResourceData object and attempts type cast to int64
if value is not present on provided resource, ErrNotFound is returned if casting is not successful, ErrInvalidType is returned
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 GetIntValueAsInt64 ¶
func GetIntValueAsInt64(key string, rd ResourceDataFetcher) (int64, error)
GetIntValueAsInt64 fetches value with given key from ResourceData object and attempts type cast to int, if succeed, it returns value as int64
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 GetMapValue ¶
func GetMapValue(key string, rd ResourceDataFetcher) (map[string]interface{}, error)
GetMapValue fetches value with given key from ResourceData object and attempts type cast to map[string]interface{}
if value is not present on provided resource, ErrNotFound is returned if casting is not successful, ErrInvalidType is returned
func GetSchemaFieldNameFromPath ¶
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 GetTypedListValue ¶
func GetTypedListValue[T any](key string, rd ResourceDataFetcher) ([]T, error)
GetTypedListValue fetches value with given key from ResourceData object and attempts to create []T
if value is not present on provided resource, ErrNotFound is returned if casting is not successful, ErrInvalidType is returned
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 ¶
MaxDuration returns the larger of x or y.
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 ¶
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 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 ValidateMapMinimalLength ¶
func ValidateMapMinimalLength(min int) schema.SchemaValidateDiagFunc
ValidateMapMinimalLength validates the map by checking if it contains at least provided number of entries
func ValidateNetwork ¶
func ValidateNetwork(i interface{}, _ cty.Path) diag.Diagnostics
ValidateNetwork defines network validation logic
func ValidateRuleFormat ¶
func ValidateRuleFormat(v interface{}, _ cty.Path) diag.Diagnostics
ValidateRuleFormat checks if value is a valid rule format of form vYYYY-MM-DD Empty string ("") is considered valid as well
func ValidateRuleFormatAcceptLatest ¶
func ValidateRuleFormatAcceptLatest(v interface{}, _ cty.Path) diag.Diagnostics
ValidateRuleFormatAcceptLatest checks if value is a valid rule format of form vYYYY-MM-DD or 'latest' Empty string ("") is considered valid as well
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 RawConfig ¶
type RawConfig struct {
// contains filtered or unexported fields
}
RawConfig is used to query attributes from the raw config.
func NewRawConfig ¶
func NewRawConfig(g RawConfigGetter) *RawConfig
NewRawConfig creates a new RawConfig which uses the raw config retrieved from data.
type RawConfigGetter ¶
RawConfigGetter is used to retrieve raw config.
type ResourceChangeFetcher ¶
ResourceChangeFetcher allows getting changes to the resource data.
type ResourceDataFetcher ¶
ResourceDataFetcher allows getting values from resource data.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package validators contains custom terraform schema validators
|
Package validators contains custom terraform schema validators |