types

package
Version: v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MPL-2.0 Imports: 11 Imported by: 141

Documentation

Overview

Package types contains the framework-defined data types and values, such as boolean, floating point, integer, list, map, object, set, and string. These types can be extended by providers for custom use cases.

Index

Constants

View Source
const (
	// StringType represents a UTF-8 string type.
	StringType primitive = iota

	// NumberType represents a number type, either an integer or a float.
	NumberType

	// BoolType represents a boolean type.
	BoolType

	// Int64Type represents a 64-bit integer.
	Int64Type

	// Float64Type represents a 64-bit floating point.
	Float64Type
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	// contains filtered or unexported fields
}

Bool represents a boolean value.

func BoolNull added in v0.15.0

func BoolNull() Bool

BoolNull creates a Bool with a null value. Determine whether the value is null via the Bool type IsNull method.

Setting the deprecated Bool type Null, Unknown, or Value fields after creating a Bool with this function has no effect.

func BoolUnknown added in v0.15.0

func BoolUnknown() Bool

BoolUnknown creates a Bool with an unknown value. Determine whether the value is unknown via the Bool type IsUnknown method.

Setting the deprecated Bool type Null, Unknown, or Value fields after creating a Bool with this function has no effect.

func BoolValue added in v0.15.0

func BoolValue(value bool) Bool

BoolValue creates a Bool with a known value. Access the value via the Bool type ValueBool method.

Setting the deprecated Bool type Null, Unknown, or Value fields after creating a Bool with this function has no effect.

func (Bool) Equal

func (b Bool) Equal(other attr.Value) bool

Equal returns true if `other` is a *Bool and has the same value as `b`.

func (Bool) IsNull added in v0.9.0

func (b Bool) IsNull() bool

IsNull returns true if the Bool represents a null value.

func (Bool) IsUnknown added in v0.9.0

func (b Bool) IsUnknown() bool

IsUnknown returns true if the Bool represents a currently unknown value.

func (Bool) String added in v0.9.0

func (b Bool) String() string

String returns a human-readable representation of the Bool value. The string returned here is not protected by any compatibility guarantees, and is intended for logging and error reporting.

func (Bool) ToBoolValue added in v0.16.0

func (b Bool) ToBoolValue(context.Context) (Bool, diag.Diagnostics)

ToBoolValue returns Bool.

func (Bool) ToTerraformValue

func (b Bool) ToTerraformValue(_ context.Context) (tftypes.Value, error)

ToTerraformValue returns the data contained in the Bool as a tftypes.Value.

func (Bool) Type added in v0.3.0

func (b Bool) Type(_ context.Context) attr.Type

Type returns a BoolType.

func (Bool) ValueBool added in v0.15.0

func (b Bool) ValueBool() bool

ValueBool returns the known bool value. If Bool is null or unknown, returns false.

type BoolTypable added in v0.16.0

type BoolTypable interface {
	attr.Type

	// ValueFromBool should convert the Bool to a BoolValuable type.
	ValueFromBool(context.Context, Bool) (BoolValuable, diag.Diagnostics)
}

BoolTypable extends attr.Type for bool types. Implement this interface to create a custom BoolType type.

type BoolValuable added in v0.16.0

type BoolValuable interface {
	attr.Value

	// ToBoolValue should convert the value type to a Bool.
	ToBoolValue(ctx context.Context) (Bool, diag.Diagnostics)
}

BoolValuable extends attr.Value for boolean value types. Implement this interface to create a custom Bool value type.

type Float64 added in v0.4.0

type Float64 struct {
	// contains filtered or unexported fields
}

Float64 represents a 64-bit floating point value, exposed as a float64.

func Float64Null added in v0.15.0

func Float64Null() Float64

Float64Null creates a Float64 with a null value. Determine whether the value is null via the Float64 type IsNull method.

Setting the deprecated Float64 type Null, Unknown, or Value fields after creating a Float64 with this function has no effect.

func Float64Unknown added in v0.15.0

func Float64Unknown() Float64

Float64Unknown creates a Float64 with an unknown value. Determine whether the value is unknown via the Float64 type IsUnknown method.

Setting the deprecated Float64 type Null, Unknown, or Value fields after creating a Float64 with this function has no effect.

func Float64Value added in v0.15.0

func Float64Value(value float64) Float64

Float64Value creates a Float64 with a known value. Access the value via the Float64 type ValueFloat64 method.

Setting the deprecated Float64 type Null, Unknown, or Value fields after creating a Float64 with this function has no effect.

func (Float64) Equal added in v0.4.0

func (f Float64) Equal(other attr.Value) bool

Equal returns true if `other` is a Float64 and has the same value as `f`.

func (Float64) IsNull added in v0.9.0

func (f Float64) IsNull() bool

IsNull returns true if the Float64 represents a null value.

func (Float64) IsUnknown added in v0.9.0

func (f Float64) IsUnknown() bool

IsUnknown returns true if the Float64 represents a currently unknown value.

func (Float64) String added in v0.9.0

func (f Float64) String() string

String returns a human-readable representation of the Float64 value. The string returned here is not protected by any compatibility guarantees, and is intended for logging and error reporting.

func (Float64) ToFloat64Value added in v0.16.0

func (f Float64) ToFloat64Value(context.Context) (Float64, diag.Diagnostics)

ToFloat64Value returns Float64.

func (Float64) ToTerraformValue added in v0.4.0

func (f Float64) ToTerraformValue(ctx context.Context) (tftypes.Value, error)

ToTerraformValue returns the data contained in the Float64 as a tftypes.Value.

func (Float64) Type added in v0.4.0

func (f Float64) Type(ctx context.Context) attr.Type

Type returns a Float64Type.

func (Float64) ValueFloat64 added in v0.15.0

func (f Float64) ValueFloat64() float64

ValueFloat64 returns the known float64 value. If Float64 is null or unknown, returns 0.0.

type Float64Typable added in v0.16.0

type Float64Typable interface {
	xattr.TypeWithValidate

	// ValueFromFloat64 should convert the Float64 to a Float64Valuable type.
	ValueFromFloat64(context.Context, Float64) (Float64Valuable, diag.Diagnostics)
}

Float64Typable extends attr.Type for float64 types. Implement this interface to create a custom Float64Type type.

type Float64Valuable added in v0.16.0

type Float64Valuable interface {
	attr.Value

	// ToFloat64Value should convert the value type to a Float64.
	ToFloat64Value(ctx context.Context) (Float64, diag.Diagnostics)
}

Float64Valuable extends attr.Value for float64 value types. Implement this interface to create a custom Float64 value type.

type Int64 added in v0.4.0

type Int64 struct {
	// contains filtered or unexported fields
}

Int64 represents a 64-bit integer value, exposed as an int64.

func Int64Null added in v0.15.0

func Int64Null() Int64

Int64Null creates a Int64 with a null value. Determine whether the value is null via the Int64 type IsNull method.

Setting the deprecated Int64 type Null, Unknown, or Value fields after creating a Int64 with this function has no effect.

func Int64Unknown added in v0.15.0

func Int64Unknown() Int64

Int64Unknown creates a Int64 with an unknown value. Determine whether the value is unknown via the Int64 type IsUnknown method.

Setting the deprecated Int64 type Null, Unknown, or Value fields after creating a Int64 with this function has no effect.

func Int64Value added in v0.15.0

func Int64Value(value int64) Int64

Int64Value creates a Int64 with a known value. Access the value via the Int64 type ValueInt64 method.

Setting the deprecated Int64 type Null, Unknown, or Value fields after creating a Int64 with this function has no effect.

func (Int64) Equal added in v0.4.0

func (i Int64) Equal(other attr.Value) bool

Equal returns true if `other` is an Int64 and has the same value as `i`.

func (Int64) IsNull added in v0.9.0

func (i Int64) IsNull() bool

IsNull returns true if the Int64 represents a null value.

func (Int64) IsUnknown added in v0.9.0

func (i Int64) IsUnknown() bool

IsUnknown returns true if the Int64 represents a currently unknown value.

func (Int64) String added in v0.9.0

func (i Int64) String() string

String returns a human-readable representation of the Int64 value. The string returned here is not protected by any compatibility guarantees, and is intended for logging and error reporting.

func (Int64) ToInt64Value added in v0.16.0

func (i Int64) ToInt64Value(context.Context) (Int64, diag.Diagnostics)

ToInt64Value returns Int64.

func (Int64) ToTerraformValue added in v0.4.0

func (i Int64) ToTerraformValue(ctx context.Context) (tftypes.Value, error)

ToTerraformValue returns the data contained in the Int64 as a tftypes.Value.

func (Int64) Type added in v0.4.0

func (i Int64) Type(ctx context.Context) attr.Type

Type returns a Int64Type.

func (Int64) ValueInt64 added in v0.15.0

func (i Int64) ValueInt64() int64

ValueInt64 returns the known float64 value. If Int64 is null or unknown, returns 0.0.

type Int64Typable added in v0.16.0

type Int64Typable interface {
	xattr.TypeWithValidate

	// ValueFromInt64 should convert the Int64 to a Int64Valuable type.
	ValueFromInt64(context.Context, Int64) (Int64Valuable, diag.Diagnostics)
}

Int64Typable extends attr.Type for int64 types. Implement this interface to create a custom Int64Type type.

type Int64Valuable added in v0.16.0

type Int64Valuable interface {
	attr.Value

	// ToInt64Value should convert the value type to an Int64.
	ToInt64Value(ctx context.Context) (Int64, diag.Diagnostics)
}

Int64Valuable extends attr.Value for int64 value types. Implement this interface to create a custom Int64 value type.

type List

type List struct {
	// contains filtered or unexported fields
}

List represents a list of attr.Values, all of the same type, indicated by ElemType.

func ListNull added in v0.15.0

func ListNull(elementType attr.Type) List

ListNull creates a List with a null value. Determine whether the value is null via the List type IsNull method.

func ListUnknown added in v0.15.0

func ListUnknown(elementType attr.Type) List

ListUnknown creates a List with an unknown value. Determine whether the value is unknown via the List type IsUnknown method.

func ListValue added in v0.15.0

func ListValue(elementType attr.Type, elements []attr.Value) (List, diag.Diagnostics)

ListValue creates a List with a known value. Access the value via the List type Elements or ElementsAs methods.

func ListValueFrom added in v0.15.0

func ListValueFrom(ctx context.Context, elementType attr.Type, elements any) (List, diag.Diagnostics)

ListValueFrom creates a List with a known value, using reflection rules. The elements must be a slice which can convert into the given element type. Access the value via the List type Elements or ElementsAs methods.

func ListValueMust added in v0.15.0

func ListValueMust(elementType attr.Type, elements []attr.Value) List

ListValueMust creates a List with a known value, converting any diagnostics into a panic at runtime. Access the value via the List type Elements or ElementsAs methods.

This creation function is only recommended to create List values which will not potentially affect practitioners, such as testing, or exhaustively tested provider logic.

func (List) ElementType added in v0.15.0

func (l List) ElementType(_ context.Context) attr.Type

ElementType returns the element type for the List.

func (List) Elements added in v0.15.0

func (l List) Elements() []attr.Value

Elements returns the collection of elements for the List. Returns nil if the List is null or unknown.

func (List) ElementsAs

func (l List) ElementsAs(ctx context.Context, target interface{}, allowUnhandled bool) diag.Diagnostics

ElementsAs populates `target` with the elements of the List, throwing an error if the elements cannot be stored in `target`.

func (List) Equal

func (l List) Equal(o attr.Value) bool

Equal returns true if the List is considered semantically equal (same type and same value) to the attr.Value passed as an argument.

func (List) IsNull added in v0.9.0

func (l List) IsNull() bool

IsNull returns true if the List represents a null value.

func (List) IsUnknown added in v0.9.0

func (l List) IsUnknown() bool

IsUnknown returns true if the List represents a currently unknown value. Returns false if the List has a known number of elements, even if all are unknown values.

func (List) String added in v0.9.0

func (l List) String() string

String returns a human-readable representation of the List value. The string returned here is not protected by any compatibility guarantees, and is intended for logging and error reporting.

func (List) ToListValue added in v0.16.0

func (l List) ToListValue(context.Context) (List, diag.Diagnostics)

ToListValue returns the List.

func (List) ToTerraformValue

func (l List) ToTerraformValue(ctx context.Context) (tftypes.Value, error)

ToTerraformValue returns the data contained in the List as a tftypes.Value.

func (List) Type added in v0.3.0

func (l List) Type(ctx context.Context) attr.Type

Type returns a ListType with the same element type as `l`.

type ListTypable added in v0.16.0

type ListTypable interface {
	attr.Type

	// ValueFromList should convert the List to a ListValuable type.
	ValueFromList(context.Context, List) (ListValuable, diag.Diagnostics)
}

ListTypable extends attr.Type for list types. Implement this interface to create a custom ListType type.

type ListType

type ListType struct {
	ElemType attr.Type
}

ListType is an AttributeType representing a list of values. All values must be of the same type, which the provider must specify as the ElemType property.

func (ListType) ApplyTerraform5AttributePathStep

func (l ListType) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error)

ApplyTerraform5AttributePathStep applies the given AttributePathStep to the list.

func (ListType) ElementType

func (l ListType) ElementType() attr.Type

ElementType returns the attr.Type elements will be created from.

func (ListType) Equal

func (l ListType) Equal(o attr.Type) bool

Equal returns true if `o` is also a ListType and has the same ElemType.

func (ListType) String added in v0.4.0

func (l ListType) String() string

String returns a human-friendly description of the ListType.

func (ListType) TerraformType

func (l ListType) TerraformType(ctx context.Context) tftypes.Type

TerraformType returns the tftypes.Type that should be used to represent this type. This constrains what user input will be accepted and what kind of data can be set in state. The framework will use this to translate the AttributeType to something Terraform can understand.

func (ListType) Validate added in v0.13.0

func (l ListType) Validate(ctx context.Context, in tftypes.Value, path path.Path) diag.Diagnostics

Validate validates all elements of the list that are of type xattr.TypeWithValidate.

func (ListType) ValueFromList added in v0.16.0

func (l ListType) ValueFromList(_ context.Context, list List) (ListValuable, diag.Diagnostics)

ValueFromList returns a ListValuable type given a List.

func (ListType) ValueFromTerraform

func (l ListType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error)

ValueFromTerraform returns an attr.Value given a tftypes.Value. This is meant to convert the tftypes.Value into a more convenient Go type for the provider to consume the data with.

func (ListType) ValueType added in v0.14.0

func (l ListType) ValueType(_ context.Context) attr.Value

ValueType returns the Value type.

func (ListType) WithElementType

func (l ListType) WithElementType(typ attr.Type) attr.TypeWithElementType

WithElementType returns a ListType that is identical to `l`, but with the element type set to `typ`.

type ListValuable added in v0.16.0

type ListValuable interface {
	attr.Value

	// ToListValue should convert the value type to a List.
	ToListValue(ctx context.Context) (List, diag.Diagnostics)
}

ListValuable extends attr.Value for list value types. Implement this interface to create a custom List value type.

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map represents a mapping of string keys to attr.Value values of a single type.

func MapNull added in v0.15.0

func MapNull(elementType attr.Type) Map

MapNull creates a Map with a null value. Determine whether the value is null via the Map type IsNull method.

func MapUnknown added in v0.15.0

func MapUnknown(elementType attr.Type) Map

MapUnknown creates a Map with an unknown value. Determine whether the value is unknown via the Map type IsUnknown method.

func MapValue added in v0.15.0

func MapValue(elementType attr.Type, elements map[string]attr.Value) (Map, diag.Diagnostics)

MapValue creates a Map with a known value. Access the value via the Map type Elements or ElementsAs methods.

func MapValueFrom added in v0.15.0

func MapValueFrom(ctx context.Context, elementType attr.Type, elements any) (Map, diag.Diagnostics)

MapValueFrom creates a Map with a known value, using reflection rules. The elements must be a map of string keys to values which can convert into the given element type. Access the value via the Map type Elements or ElementsAs methods.

func MapValueMust added in v0.15.0

func MapValueMust(elementType attr.Type, elements map[string]attr.Value) Map

MapValueMust creates a Map with a known value, converting any diagnostics into a panic at runtime. Access the value via the Map type Elements or ElementsAs methods.

This creation function is only recommended to create Map values which will not potentially effect practitioners, such as testing, or exhaustively tested provider logic.

func (Map) ElementType added in v0.15.0

func (m Map) ElementType(_ context.Context) attr.Type

ElementType returns the element type for the Map.

func (Map) Elements added in v0.15.0

func (m Map) Elements() map[string]attr.Value

Elements returns the mapping of elements for the Map. Returns nil if the Map is null or unknown.

func (Map) ElementsAs

func (m Map) ElementsAs(ctx context.Context, target interface{}, allowUnhandled bool) diag.Diagnostics

ElementsAs populates `target` with the elements of the Map, throwing an error if the elements cannot be stored in `target`.

func (Map) Equal

func (m Map) Equal(o attr.Value) bool

Equal returns true if the Map is considered semantically equal (same type and same value) to the attr.Value passed as an argument.

func (Map) IsNull added in v0.9.0

func (m Map) IsNull() bool

IsNull returns true if the Map represents a null value.

func (Map) IsUnknown added in v0.9.0

func (m Map) IsUnknown() bool

IsUnknown returns true if the Map represents a currently unknown value. Returns false if the Map has a known number of elements, even if all are unknown values.

func (Map) String added in v0.9.0

func (m Map) String() string

String returns a human-readable representation of the Map value. The string returned here is not protected by any compatibility guarantees, and is intended for logging and error reporting.

func (Map) ToMapValue added in v0.16.0

func (m Map) ToMapValue(context.Context) (Map, diag.Diagnostics)

ToMapValue returns the Map.

func (Map) ToTerraformValue

func (m Map) ToTerraformValue(ctx context.Context) (tftypes.Value, error)

ToTerraformValue returns the data contained in the Map as a tftypes.Value.

func (Map) Type added in v0.3.0

func (m Map) Type(ctx context.Context) attr.Type

Type returns a MapType with the same element type as `m`.

type MapTypable added in v0.16.0

type MapTypable interface {
	attr.Type

	// ValueFromMap should convert the Map to a MapValuable type.
	ValueFromMap(context.Context, Map) (MapValuable, diag.Diagnostics)
}

MapTypable extends attr.Type for map types. Implement this interface to create a custom MapType type.

type MapType

type MapType struct {
	ElemType attr.Type
}

MapType is an AttributeType representing a map of values. All values must be of the same type, which the provider must specify as the ElemType property. Keys will always be strings.

func (MapType) ApplyTerraform5AttributePathStep

func (m MapType) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error)

ApplyTerraform5AttributePathStep applies the given AttributePathStep to the map.

func (MapType) ElementType

func (m MapType) ElementType() attr.Type

ElementType returns the type's element type.

func (MapType) Equal

func (m MapType) Equal(o attr.Type) bool

Equal returns true if `o` is also a MapType and has the same ElemType.

func (MapType) String added in v0.4.0

func (m MapType) String() string

String returns a human-friendly description of the MapType.

func (MapType) TerraformType

func (m MapType) TerraformType(ctx context.Context) tftypes.Type

TerraformType returns the tftypes.Type that should be used to represent this type. This constrains what user input will be accepted and what kind of data can be set in state. The framework will use this to translate the AttributeType to something Terraform can understand.

func (MapType) Validate added in v0.13.0

func (m MapType) Validate(ctx context.Context, in tftypes.Value, path path.Path) diag.Diagnostics

Validate validates all elements of the map that are of type xattr.TypeWithValidate.

func (MapType) ValueFromMap added in v0.16.0

func (m MapType) ValueFromMap(_ context.Context, ma Map) (MapValuable, diag.Diagnostics)

ValueFromMap returns a MapValuable type given a Map.

func (MapType) ValueFromTerraform

func (m MapType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error)

ValueFromTerraform returns an attr.Value given a tftypes.Value. This is meant to convert the tftypes.Value into a more convenient Go type for the provider to consume the data with.

func (MapType) ValueType added in v0.14.0

func (m MapType) ValueType(_ context.Context) attr.Value

ValueType returns the Value type.

func (MapType) WithElementType

func (m MapType) WithElementType(typ attr.Type) attr.TypeWithElementType

WithElementType returns a new copy of the type with its element type set.

type MapValuable added in v0.16.0

type MapValuable interface {
	attr.Value

	// ToMapValue should convert the value type to a Map.
	ToMapValue(ctx context.Context) (Map, diag.Diagnostics)
}

MapValuable extends attr.Value for map value types. Implement this interface to create a custom Map value type.

type Number

type Number struct {
	// contains filtered or unexported fields
}

Number represents a number value, exposed as a *big.Float. Numbers can be floats or integers.

func NumberNull added in v0.15.0

func NumberNull() Number

NumberNull creates a Number with a null value. Determine whether the value is null via the Number type IsNull method.

Setting the deprecated Number type Null, Unknown, or Value fields after creating a Number with this function has no effect.

func NumberUnknown added in v0.15.0

func NumberUnknown() Number

NumberUnknown creates a Number with an unknown value. Determine whether the value is unknown via the Number type IsUnknown method.

Setting the deprecated Number type Null, Unknown, or Value fields after creating a Number with this function has no effect.

func NumberValue added in v0.15.0

func NumberValue(value *big.Float) Number

NumberValue creates a Number with a known value. Access the value via the Number type ValueBigFloat method. If the given value is nil, a null Number is created.

Setting the deprecated Number type Null, Unknown, or Value fields after creating a Number with this function has no effect.

func (Number) Equal

func (n Number) Equal(other attr.Value) bool

Equal returns true if `other` is a Number and has the same value as `n`.

func (Number) IsNull added in v0.9.0

func (n Number) IsNull() bool

IsNull returns true if the Number represents a null value.

func (Number) IsUnknown added in v0.9.0

func (n Number) IsUnknown() bool

IsUnknown returns true if the Number represents a currently unknown value.

func (Number) String added in v0.9.0

func (n Number) String() string

String returns a human-readable representation of the Number value. The string returned here is not protected by any compatibility guarantees, and is intended for logging and error reporting.

func (Number) ToNumberValue added in v0.16.0

func (n Number) ToNumberValue(context.Context) (Number, diag.Diagnostics)

ToNumberValue returns Number.

func (Number) ToTerraformValue

func (n Number) ToTerraformValue(_ context.Context) (tftypes.Value, error)

ToTerraformValue returns the data contained in the Number as a tftypes.Value.

func (Number) Type added in v0.3.0

func (n Number) Type(_ context.Context) attr.Type

Type returns a NumberType.

func (Number) ValueBigFloat added in v0.15.0

func (n Number) ValueBigFloat() *big.Float

ValueBigFloat returns the known *big.Float value. If Number is null or unknown, returns 0.0.

type NumberTypable added in v0.16.0

type NumberTypable interface {
	attr.Type

	// ValueFromNumber should convert the Number to a NumberValuable type.
	ValueFromNumber(context.Context, Number) (NumberValuable, diag.Diagnostics)
}

NumberTypable extends attr.Type for number types. Implement this interface to create a custom NumberType type.

type NumberValuable added in v0.16.0

type NumberValuable interface {
	attr.Value

	// ToNumberValue should convert the value type to a Number.
	ToNumberValue(ctx context.Context) (Number, diag.Diagnostics)
}

NumberValuable extends attr.Value for number value types. Implement this interface to create a custom Number value type.

type Object

type Object struct {
	// contains filtered or unexported fields
}

Object represents an object

func ObjectNull added in v0.15.0

func ObjectNull(attributeTypes map[string]attr.Type) Object

ObjectNull creates a Object with a null value. Determine whether the value is null via the Object type IsNull method.

func ObjectUnknown added in v0.15.0

func ObjectUnknown(attributeTypes map[string]attr.Type) Object

ObjectUnknown creates a Object with an unknown value. Determine whether the value is unknown via the Object type IsUnknown method.

func ObjectValue added in v0.15.0

func ObjectValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (Object, diag.Diagnostics)

ObjectValue creates a Object with a known value. Access the value via the Object type ElementsAs method.

func ObjectValueFrom added in v0.15.0

func ObjectValueFrom(ctx context.Context, attributeTypes map[string]attr.Type, attributes any) (Object, diag.Diagnostics)

ObjectValueFrom creates a Object with a known value, using reflection rules. The attributes must be a map of string attribute names to attribute values which can convert into the given attribute type or a struct with tfsdk field tags. Access the value via the Object type Elements or ElementsAs methods.

func ObjectValueMust added in v0.15.0

func ObjectValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) Object

ObjectValueMust creates a Object with a known value, converting any diagnostics into a panic at runtime. Access the value via the Object type Elements or ElementsAs methods.

This creation function is only recommended to create Object values which will not potentially effect practitioners, such as testing, or exhaustively tested provider logic.

func (Object) As

func (o Object) As(ctx context.Context, target interface{}, opts ObjectAsOptions) diag.Diagnostics

As populates `target` with the data in the Object, throwing an error if the data cannot be stored in `target`.

func (Object) AttributeTypes added in v0.15.0

func (o Object) AttributeTypes(_ context.Context) map[string]attr.Type

AttributeTypes returns the mapping of attribute types for the Object.

func (Object) Attributes added in v0.15.0

func (o Object) Attributes() map[string]attr.Value

Attributes returns the mapping of known attribute values for the Object. Returns nil if the Object is null or unknown.

func (Object) Equal

func (o Object) Equal(c attr.Value) bool

Equal returns true if the Object is considered semantically equal (same type and same value) to the attr.Value passed as an argument.

func (Object) IsNull added in v0.9.0

func (o Object) IsNull() bool

IsNull returns true if the Object represents a null value.

func (Object) IsUnknown added in v0.9.0

func (o Object) IsUnknown() bool

IsUnknown returns true if the Object represents a currently unknown value.

func (Object) String added in v0.9.0

func (o Object) String() string

String returns a human-readable representation of the Object value. The string returned here is not protected by any compatibility guarantees, and is intended for logging and error reporting.

func (Object) ToObjectValue added in v0.16.0

func (o Object) ToObjectValue(context.Context) (Object, diag.Diagnostics)

ToObjectValue returns the Object.

func (Object) ToTerraformValue

func (o Object) ToTerraformValue(ctx context.Context) (tftypes.Value, error)

ToTerraformValue returns the data contained in the attr.Value as a tftypes.Value.

func (Object) Type added in v0.3.0

func (o Object) Type(ctx context.Context) attr.Type

Type returns an ObjectType with the same attribute types as `o`.

type ObjectAsOptions

type ObjectAsOptions struct {
	// UnhandledNullAsEmpty controls what happens when As needs to put a
	// null value in a type that has no way to preserve that distinction.
	// When set to true, the type's empty value will be used.  When set to
	// false, an error will be returned.
	UnhandledNullAsEmpty bool

	// UnhandledUnknownAsEmpty controls what happens when As needs to put
	// an unknown value in a type that has no way to preserve that
	// distinction. When set to true, the type's empty value will be used.
	// When set to false, an error will be returned.
	UnhandledUnknownAsEmpty bool
}

ObjectAsOptions is a collection of toggles to control the behavior of Object.As.

type ObjectTypable added in v0.16.0

type ObjectTypable interface {
	attr.Type

	// ValueFromObject should convert the Object to an ObjectValuable type.
	ValueFromObject(context.Context, Object) (ObjectValuable, diag.Diagnostics)
}

ObjectTypable extends attr.Type for object types. Implement this interface to create a custom ObjectType type.

type ObjectType

type ObjectType struct {
	AttrTypes map[string]attr.Type
}

ObjectType is an AttributeType representing an object.

func (ObjectType) ApplyTerraform5AttributePathStep

func (o ObjectType) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error)

ApplyTerraform5AttributePathStep applies the given AttributePathStep to the object.

func (ObjectType) AttributeTypes

func (o ObjectType) AttributeTypes() map[string]attr.Type

AttributeTypes returns the type's attribute types.

func (ObjectType) Equal

func (o ObjectType) Equal(candidate attr.Type) bool

Equal returns true if `candidate` is also an ObjectType and has the same AttributeTypes.

func (ObjectType) String added in v0.4.0

func (o ObjectType) String() string

String returns a human-friendly description of the ObjectType.

func (ObjectType) TerraformType

func (o ObjectType) TerraformType(ctx context.Context) tftypes.Type

TerraformType returns the tftypes.Type that should be used to represent this type. This constrains what user input will be accepted and what kind of data can be set in state. The framework will use this to translate the AttributeType to something Terraform can understand.

func (ObjectType) ValueFromObject added in v0.16.0

func (o ObjectType) ValueFromObject(_ context.Context, obj Object) (ObjectValuable, diag.Diagnostics)

ValueFromObject returns an ObjectValuable type given an Object.

func (ObjectType) ValueFromTerraform

func (o ObjectType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error)

ValueFromTerraform returns an attr.Value given a tftypes.Value. This is meant to convert the tftypes.Value into a more convenient Go type for the provider to consume the data with.

func (ObjectType) ValueType added in v0.14.0

func (o ObjectType) ValueType(_ context.Context) attr.Value

ValueType returns the Value type.

func (ObjectType) WithAttributeTypes

func (o ObjectType) WithAttributeTypes(typs map[string]attr.Type) attr.TypeWithAttributeTypes

WithAttributeTypes returns a new copy of the type with its attribute types set.

type ObjectValuable added in v0.16.0

type ObjectValuable interface {
	attr.Value

	// ToObjectValue should convert the value type to an Object.
	ToObjectValue(ctx context.Context) (Object, diag.Diagnostics)
}

ObjectValuable extends attr.Value for object value types. Implement this interface to create a custom Object value type.

type Set added in v0.4.0

type Set struct {
	// contains filtered or unexported fields
}

Set represents a set of attr.Value, all of the same type, indicated by ElemType.

func SetNull added in v0.15.0

func SetNull(elementType attr.Type) Set

SetNull creates a Set with a null value. Determine whether the value is null via the Set type IsNull method.

func SetUnknown added in v0.15.0

func SetUnknown(elementType attr.Type) Set

SetUnknown creates a Set with an unknown value. Determine whether the value is unknown via the Set type IsUnknown method.

func SetValue added in v0.15.0

func SetValue(elementType attr.Type, elements []attr.Value) (Set, diag.Diagnostics)

SetValue creates a Set with a known value. Access the value via the Set type Elements or ElementsAs methods.

func SetValueFrom added in v0.15.0

func SetValueFrom(ctx context.Context, elementType attr.Type, elements any) (Set, diag.Diagnostics)

SetValueFrom creates a Set with a known value, using reflection rules. The elements must be a slice which can convert into the given element type. Access the value via the Set type Elements or ElementsAs methods.

func SetValueMust added in v0.15.0

func SetValueMust(elementType attr.Type, elements []attr.Value) Set

SetValueMust creates a Set with a known value, converting any diagnostics into a panic at runtime. Access the value via the Set type Elements or ElementsAs methods.

This creation function is only recommended to create Set values which will not potentially effect practitioners, such as testing, or exhaustively tested provider logic.

func (Set) ElementType added in v0.15.0

func (s Set) ElementType(_ context.Context) attr.Type

ElementType returns the element type for the Set.

func (Set) Elements added in v0.15.0

func (s Set) Elements() []attr.Value

Elements returns the collection of elements for the Set. Returns nil if the Set is null or unknown.

func (Set) ElementsAs added in v0.4.0

func (s Set) ElementsAs(ctx context.Context, target interface{}, allowUnhandled bool) diag.Diagnostics

ElementsAs populates `target` with the elements of the Set, throwing an error if the elements cannot be stored in `target`.

func (Set) Equal added in v0.4.0

func (s Set) Equal(o attr.Value) bool

Equal returns true if the Set is considered semantically equal (same type and same value) to the attr.Value passed as an argument.

func (Set) IsNull added in v0.9.0

func (s Set) IsNull() bool

IsNull returns true if the Set represents a null value.

func (Set) IsUnknown added in v0.9.0

func (s Set) IsUnknown() bool

IsUnknown returns true if the Set represents a currently unknown value. Returns false if the Set has a known number of elements, even if all are unknown values.

func (Set) String added in v0.9.0

func (s Set) String() string

String returns a human-readable representation of the Set value. The string returned here is not protected by any compatibility guarantees, and is intended for logging and error reporting.

func (Set) ToSetValue added in v0.16.0

func (s Set) ToSetValue(context.Context) (Set, diag.Diagnostics)

ToSetValue returns the Set.

func (Set) ToTerraformValue added in v0.4.0

func (s Set) ToTerraformValue(ctx context.Context) (tftypes.Value, error)

ToTerraformValue returns the data contained in the Set as a tftypes.Value.

func (Set) Type added in v0.4.0

func (s Set) Type(ctx context.Context) attr.Type

Type returns a SetType with the same element type as `s`.

type SetTypable added in v0.16.0

type SetTypable interface {
	attr.Type

	// ValueFromSet should convert the Set to a SetValuable type.
	ValueFromSet(context.Context, Set) (SetValuable, diag.Diagnostics)
}

SetTypable extends attr.Type for set types. Implement this interface to create a custom SetType type.

type SetType added in v0.4.0

type SetType struct {
	ElemType attr.Type
}

SetType is an AttributeType representing a set of values. All values must be of the same type, which the provider must specify as the ElemType property.

func (SetType) ApplyTerraform5AttributePathStep added in v0.4.0

func (st SetType) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error)

ApplyTerraform5AttributePathStep applies the given AttributePathStep to the set.

func (SetType) ElementType added in v0.4.0

func (st SetType) ElementType() attr.Type

ElementType returns the attr.Type elements will be created from.

func (SetType) Equal added in v0.4.0

func (st SetType) Equal(o attr.Type) bool

Equal returns true if `o` is also a SetType and has the same ElemType.

func (SetType) String added in v0.4.0

func (st SetType) String() string

String returns a human-friendly description of the SetType.

func (SetType) TerraformType added in v0.4.0

func (st SetType) TerraformType(ctx context.Context) tftypes.Type

TerraformType returns the tftypes.Type that should be used to represent this type. This constrains what user input will be accepted and what kind of data can be set in state. The framework will use this to translate the AttributeType to something Terraform can understand.

func (SetType) Validate added in v0.4.0

func (st SetType) Validate(ctx context.Context, in tftypes.Value, path path.Path) diag.Diagnostics

Validate implements type validation. This type requires all elements to be unique.

func (SetType) ValueFromSet added in v0.16.0

func (st SetType) ValueFromSet(_ context.Context, set Set) (SetValuable, diag.Diagnostics)

ValueFromSet returns a SetValuable type given a Set.

func (SetType) ValueFromTerraform added in v0.4.0

func (st SetType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error)

ValueFromTerraform returns an attr.Value given a tftypes.Value. This is meant to convert the tftypes.Value into a more convenient Go type for the provider to consume the data with.

func (SetType) ValueType added in v0.14.0

func (st SetType) ValueType(_ context.Context) attr.Value

ValueType returns the Value type.

func (SetType) WithElementType added in v0.4.0

func (st SetType) WithElementType(typ attr.Type) attr.TypeWithElementType

WithElementType returns a SetType that is identical to `l`, but with the element type set to `typ`.

type SetValuable added in v0.16.0

type SetValuable interface {
	attr.Value

	// ToSetValue should convert the value type to a Set.
	ToSetValue(ctx context.Context) (Set, diag.Diagnostics)
}

SetValuable extends attr.Value for set value types. Implement this interface to create a custom Set value type.

type String

type String struct {
	// contains filtered or unexported fields
}

String represents a UTF-8 string value.

func StringNull added in v0.15.0

func StringNull() String

StringNull creates a String with a null value. Determine whether the value is null via the String type IsNull method.

Setting the deprecated String type Null, Unknown, or Value fields after creating a String with this function has no effect.

func StringUnknown added in v0.15.0

func StringUnknown() String

StringUnknown creates a String with an unknown value. Determine whether the value is unknown via the String type IsUnknown method.

Setting the deprecated String type Null, Unknown, or Value fields after creating a String with this function has no effect.

func StringValue added in v0.15.0

func StringValue(value string) String

StringValue creates a String with a known value. Access the value via the String type ValueString method.

Setting the deprecated String type Null, Unknown, or Value fields after creating a String with this function has no effect.

func (String) Equal

func (s String) Equal(other attr.Value) bool

Equal returns true if `other` is a String and has the same value as `s`.

func (String) IsNull added in v0.9.0

func (s String) IsNull() bool

IsNull returns true if the String represents a null value.

func (String) IsUnknown added in v0.9.0

func (s String) IsUnknown() bool

IsUnknown returns true if the String represents a currently unknown value.

func (String) String added in v0.9.0

func (s String) String() string

String returns a human-readable representation of the String value. Use the ValueString method for Terraform data handling instead.

The string returned here is not protected by any compatibility guarantees, and is intended for logging and error reporting.

func (String) ToStringValue added in v0.16.0

func (s String) ToStringValue(context.Context) (String, diag.Diagnostics)

ToStringValue returns String.

func (String) ToTerraformValue

func (s String) ToTerraformValue(_ context.Context) (tftypes.Value, error)

ToTerraformValue returns the data contained in the *String as a tftypes.Value.

func (String) Type added in v0.3.0

func (s String) Type(_ context.Context) attr.Type

Type returns a StringType.

func (String) ValueString added in v0.15.0

func (s String) ValueString() string

ValueString returns the known string value. If String is null or unknown, returns "".

type StringTypable added in v0.16.0

type StringTypable interface {
	attr.Type

	// ValueFromString should convert the String to a StringValuable type.
	ValueFromString(context.Context, String) (StringValuable, diag.Diagnostics)
}

StringTypable extends attr.Type for string types. Implement this interface to create a custom StringType type.

type StringValuable added in v0.16.0

type StringValuable interface {
	attr.Value

	// ToStringValue should convert the value type to a String.
	ToStringValue(ctx context.Context) (String, diag.Diagnostics)
}

StringValuable extends attr.Value for string value types. Implement this interface to create a custom String value type.

Jump to

Keyboard shortcuts

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