-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathnested_attribute_object.go
79 lines (67 loc) · 3.2 KB
/
nested_attribute_object.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package schema
import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema/fwxschema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
// Ensure the implementation satisifies the desired interfaces.
var _ fwxschema.NestedAttributeObjectWithValidators = NestedAttributeObject{}
// NestedAttributeObject is the object containing the underlying attributes
// for a ListNestedAttribute, MapNestedAttribute, SetNestedAttribute, or
// SingleNestedAttribute (automatically generated). When retrieving the value
// for this attribute, use types.Object as the value type unless the CustomType
// field is set. The Attributes field must be set. Nested attributes are only
// compatible with protocol version 6.
//
// This object enables customizing and simplifying details within its parent
// NestedAttribute, therefore it cannot have Terraform schema fields such as
// Required, Description, etc.
type NestedAttributeObject struct {
// Attributes is the mapping of underlying attribute names to attribute
// definitions. This field must be set.
Attributes map[string]Attribute
// CustomType enables the use of a custom attribute type in place of the
// default basetypes.ObjectType. When retrieving data, the basetypes.ObjectValuable
// associated with this custom type must be used in place of types.Object.
CustomType basetypes.ObjectTypable
// Validators define value validation functionality for the attribute. All
// elements of the slice of AttributeValidator are run, regardless of any
// previous error diagnostics.
//
// Many common use case validators can be found in the
// github.com/hashicorp/terraform-plugin-framework-validators Go module.
//
// If the Type field points to a custom type that implements the
// xattr.TypeWithValidate interface, the validators defined in this field
// are run in addition to the validation defined by the type.
Validators []validator.Object
}
// ApplyTerraform5AttributePathStep performs an AttributeName step on the
// underlying attributes or returns an error.
func (o NestedAttributeObject) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (any, error) {
return fwschema.NestedAttributeObjectApplyTerraform5AttributePathStep(o, step)
}
// Equal returns true if the given NestedAttributeObject is equivalent.
func (o NestedAttributeObject) Equal(other fwschema.NestedAttributeObject) bool {
if _, ok := other.(NestedAttributeObject); !ok {
return false
}
return fwschema.NestedAttributeObjectEqual(o, other)
}
// GetAttributes returns the Attributes field value.
func (o NestedAttributeObject) GetAttributes() fwschema.UnderlyingAttributes {
return schemaAttributes(o.Attributes)
}
// ObjectValidators returns the Validators field value.
func (o NestedAttributeObject) ObjectValidators() []validator.Object {
return o.Validators
}
// Type returns the framework type of the NestedAttributeObject.
func (o NestedAttributeObject) Type() basetypes.ObjectTypable {
if o.CustomType != nil {
return o.CustomType
}
return fwschema.NestedAttributeObjectType(o)
}