structure

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllFieldsEmpty

func AllFieldsEmpty(v interface{}) bool

AllFieldsEmpty checks to see if all fields in a given struct are zero values. It does not recurse, so finer-grained checking should be done for deep accuracy when necessary. It also does not dereference pointers, except if the value itself is a pointer and is not nil.

func BoolPolicy

func BoolPolicy(b bool) *types.BoolPolicy

BoolPolicy converts a bool into a VMware BoolPolicy value.

func BoolPtr

func BoolPtr(v bool) *bool

BoolPtr makes a *bool out of the value passed in through v.

vSphere uses nil values in bools to omit values in the SOAP XML request, and helps denote inheritance in certain cases.

func BoolStringPtrState added in v1.4.0

func BoolStringPtrState(v interface{}) string

BoolStringPtrState is a state normalization function for stringified 3-state bool pointers.

The function silently drops any result that can't be parsed with ParseBool, and will return an empty string for these cases.

This is designed to address the current lack of HCL and Terraform to be able to distinguish between nil states and zero values properly. This is a systemic issue that affects reading, writing, and diffing of these values. These issues will eventually be addressed in HCL2.

func ByteToGB

func ByteToGB(n interface{}) interface{}

ByteToGB returns n/1000000000. The input must be an integer that can be divisible by 1000000000.

Remember that int32 overflows at 2GB, so any values higher than that will produce an inaccurate result.

func ByteToGiB

func ByteToGiB(n interface{}) interface{}

ByteToGiB returns n/1024^3. The input must be an integer that can be appropriately divisible.

Remember that int32 overflows at approximately 2GiB, so any values higher than that will produce an inaccurate result.

func ByteToMB

func ByteToMB(n interface{}) interface{}

ByteToMB returns n/1000000. The input must be an integer that can be divisible by 1000000.

func DeRef

func DeRef(v interface{}) interface{}

DeRef returns the value pointed to by the interface if the interface is a pointer and is not nil, otherwise returns nil, or the direct value if it's not a pointer.

func GBToByte

func GBToByte(n interface{}) int64

GBToByte returns n*1000000000.

The output is returned as int64 - if another type is needed, it needs to be cast. Remember that int32 overflows at 2GB and uint32 will overflow at 4GB.

func GetBool

func GetBool(d *schema.ResourceData, key string) *bool

GetBool reads a ResourceData and returns a *bool. This differs from GetBoolPtr in that a nil value is never returned.

func GetBoolPolicy

func GetBoolPolicy(d *schema.ResourceData, key string) *types.BoolPolicy

GetBoolPolicy reads a ResourceData and returns an appropriate BoolPolicy for the state of the definition. nil is returned if it does not exist.

func GetBoolPolicyReverse

func GetBoolPolicyReverse(d *schema.ResourceData, key string) *types.BoolPolicy

GetBoolPolicyReverse acts like GetBoolPolicy, but the value is inverted.

func GetBoolPtr

func GetBoolPtr(d *schema.ResourceData, key string) *bool

GetBoolPtr reads a ResourceData and returns an appropriate *bool for the state of the definition. nil is returned if it does not exist.

func GetBoolStringPtr added in v1.4.0

func GetBoolStringPtr(d *schema.ResourceData, key string) (*bool, error)

GetBoolStringPtr reads a ResourceData *string* field. This field is handled in the following way:

* If it's empty, nil is returned. * The string is then sent through ParseBool. This will return a valid value for anything ParseBool returns a value for. * If it's anything else, an error is returned.

This is designed to address the current lack of HCL and Terraform to be able to distinguish between nil states and zero values properly. This is a systemic issue that affects reading, writing, and diffing of these values. These issues will eventually be addressed in HCL2.

func GetInt64Ptr

func GetInt64Ptr(d *schema.ResourceData, key string) *int64

GetInt64Ptr reads a ResourceData and returns an appropriate *int64 for the state of the definition. nil is returned if it does not exist.

func GetLongPolicy

func GetLongPolicy(d *schema.ResourceData, key string) *types.LongPolicy

GetLongPolicy reads a ResourceData and returns an appropriate LongPolicy for the state of the definition. nil is returned if it does not exist.

func GetString added in v1.4.0

func GetString(d *schema.ResourceData, key string) *string

GetString reads a ResourceData and returns a *string. This differs from GetStringPtr in that a nil value is never returned.

func GetStringPolicy

func GetStringPolicy(d *schema.ResourceData, key string) *types.StringPolicy

GetStringPolicy reads a ResourceData and returns an appropriate StringPolicy for the state of the definition. nil is returned if it does not exist.

func GetStringPtr added in v1.4.0

func GetStringPtr(d *schema.ResourceData, key string) *string

GetStringPtr reads a ResourceData and returns an appropriate *string for the state of the definition. nil is returned if it does not exist.

func GiBToByte

func GiBToByte(n interface{}) int64

GiBToByte returns n*1024^3.

The output is returned as int64 - if another type is needed, it needs to be cast. Remember that int32 overflows at around 2GiB and uint32 will overflow at 4GiB.

func Int32Ptr

func Int32Ptr(v int32) *int32

Int32Ptr makes an *int32 out of the value passed in through v.

func Int64Ptr

func Int64Ptr(v int64) *int64

Int64Ptr makes an *int64 out of the value passed in through v.

func LogCond added in v1.1.1

func LogCond(c bool, t, f interface{}) interface{}

LogCond takes a boolean (which can be passed in as a bool or as a conditional), and returns either the first value if true, and the second if false. It's designed to be a "ternary" operator of sorts for logging.

func LongPolicy

func LongPolicy(n interface{}) *types.LongPolicy

LongPolicy converts a supported number into a VMware LongPolicy value. This will panic if there is no implicit conversion of the value into an int64.

func MergeSchema

func MergeSchema(dst, src map[string]*schema.Schema)

MergeSchema merges the map[string]*schema.Schema from src into dst. Safety against conflicts is enforced by panicing.

func NormalizeValue

func NormalizeValue(v interface{}) interface{}

NormalizeValue converts a value to something that is suitable to be set in a ResourceData and can be useful in situations where there is not access to normal helper/schema functionality, but you still need saved fields to behave in the same way.

Specifically, this will run the value through DeRef to dereference any pointers first, and then convert numeric primitives, if necessary.

func ResourceIDString added in v1.4.0

func ResourceIDString(d ResourceIDStringer, name string) string

ResourceIDString prints a friendly string for a resource, supplied by name.

func SetBoolPolicy

func SetBoolPolicy(d *schema.ResourceData, key string, val *types.BoolPolicy) error

SetBoolPolicy sets a ResourceData field depending on if a BoolPolicy exists or not. The field is not set if it's nil.

func SetBoolPolicyReverse

func SetBoolPolicyReverse(d *schema.ResourceData, key string, val *types.BoolPolicy) error

SetBoolPolicyReverse acts like SetBoolPolicy, but the value is inverted.

func SetBoolPtr

func SetBoolPtr(d *schema.ResourceData, key string, val *bool) error

SetBoolPtr sets a ResourceData field depending on if a *bool exists or not. The field is not set if it's nil.

func SetBoolStringPtr added in v1.4.0

func SetBoolStringPtr(d *schema.ResourceData, key string, val *bool) error

SetBoolStringPtr sets a stringified ResoruceData bool field. This is a field that is supposed to behave like a bool (true/false), but needs to be a string to represent a nil state as well.

This is designed to address the current lack of HCL and Terraform to be able to distinguish between nil states and zero values properly. This is a systemic issue that affects reading, writing, and diffing of these values. These issues will eventually be addressed in HCL2.

func SetInt64Ptr

func SetInt64Ptr(d *schema.ResourceData, key string, val *int64) error

SetInt64Ptr sets a ResourceData field depending on if an *int64 exists or not. The field is not set if it's nil.

func SetLongPolicy

func SetLongPolicy(d *schema.ResourceData, key string, val *types.LongPolicy) error

SetLongPolicy sets a ResourceData field depending on if a LongPolicy exists or not. The field is not set if it's nil.

func SetStringPolicy

func SetStringPolicy(d *schema.ResourceData, key string, val *types.StringPolicy) error

SetStringPolicy sets a ResourceData field depending on if a StringPolicy exists or not. The field is not set if it's nil.

func SetStringPtr added in v1.4.0

func SetStringPtr(d *schema.ResourceData, key string, val *string) error

SetStringPtr sets a ResourceData field depending on if a *string exists or not. The field is not set if it's nil.

func SliceInterfacesToStrings

func SliceInterfacesToStrings(s []interface{}) []string

SliceInterfacesToStrings converts an interface slice to a string slice. The function does not attempt to do any sanity checking and will panic if one of the items in the slice is not a string.

func SliceStringsToInterfaces

func SliceStringsToInterfaces(s []string) []interface{}

SliceStringsToInterfaces converts a string slice to an interface slice.

func StringPolicy

func StringPolicy(s string) *types.StringPolicy

StringPolicy converts a string into a VMware StringPolicy value.

func StringPtr added in v1.4.0

func StringPtr(v string) *string

StringPtr makes a *string out of the value passed in through v.

vSphere uses nil values in strings to omit values in the SOAP XML request, and helps denote inheritance in certain cases.

func ValidateBoolStringPtr added in v1.4.0

func ValidateBoolStringPtr() schema.SchemaValidateFunc

ValidateBoolStringPtr validates that the input value can be parsed by ParseBool. It also succeeds on empty strings.

This is designed to address the current lack of HCL and Terraform to be able to distinguish between nil states and zero values properly. This is a systemic issue that affects reading, writing, and diffing of these values. These issues will eventually be addressed in HCL2.

Types

type ResourceIDStringer added in v1.4.0

type ResourceIDStringer interface {
	Id() string
}

ResourceIDStringer is a small interface that can be used to supply ResourceData and ResourceDiff to functions that need to print the ID of a resource, namely used by logging.

Jump to

Keyboard shortcuts

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