/
attribute.go
115 lines (93 loc) · 3.82 KB
/
attribute.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package fwschema
import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
// Attribute is the core interface required for implementing Terraform schema
// functionality that can accept a value. This is intended to be the first
// abstraction of tfsdk.Attribute functionality into data source, provider,
// and resource specific functionality.
//
// Refer to the internal/fwschema/fwxschema package for optional interfaces
// that define framework-specific functionality, such a plan modification and
// validation.
type Attribute interface {
// Implementations should include the tftypes.AttributePathStepper
// interface methods for proper path and data handling.
tftypes.AttributePathStepper
// Equal should return true if the other attribute is exactly equivalent.
Equal(o Attribute) bool
// FrameworkType should return the framework type, whether a direct type
// or nested attributes type, for the attribute.
//
// When tfsdk.Attribute is removed, this should be deprecated and renamed
// to Type() to match other interfaces.
FrameworkType() attr.Type
// GetAttributes should return the nested attributes of an attribute, if
// applicable. This is named differently than Attribute to prevent a
// conflict with the tfsdk.Attribute field name.
GetAttributes() NestedAttributes
// GetDeprecationMessage should return a non-empty string if an attribute
// is deprecated. This is named differently than DeprecationMessage to
// prevent a conflict with the tfsdk.Attribute field name.
GetDeprecationMessage() string
// GetDescription should return a non-empty string if an attribute
// has a plaintext description. This is named differently than Description
// to prevent a conflict with the tfsdk.Attribute field name.
GetDescription() string
// GetMarkdownDescription should return a non-empty string if an attribute
// has a Markdown description. This is named differently than
// MarkdownDescription to prevent a conflict with the tfsdk.Attribute field
// name.
GetMarkdownDescription() string
// GetType should return the framework type of an attribute. This is named
// differently than Type to prevent a conflict with the tfsdk.Attribute
// field name.
GetType() attr.Type
// IsComputed should return true if the attribute configuration value is
// computed. This is named differently than Computed to prevent a conflict
// with the tfsdk.Attribute field name.
IsComputed() bool
// IsOptional should return true if the attribute configuration value is
// optional. This is named differently than Optional to prevent a conflict
// with the tfsdk.Attribute field name.
IsOptional() bool
// IsRequired should return true if the attribute configuration value is
// required. This is named differently than Required to prevent a conflict
// with the tfsdk.Attribute field name.
IsRequired() bool
// IsSensitive should return true if the attribute configuration value is
// sensitive. This is named differently than Sensitive to prevent a
// conflict with the tfsdk.Attribute field name.
IsSensitive() bool
}
// AttributesEqual is a helper function to perform equality testing on two
// Attribute. Attribute Equal implementations should still compare the concrete
// types in addition to using this helper.
func AttributesEqual(a, b Attribute) bool {
if !a.GetType().Equal(b.GetType()) {
return false
}
if a.GetDeprecationMessage() != b.GetDeprecationMessage() {
return false
}
if a.GetDescription() != b.GetDescription() {
return false
}
if a.GetMarkdownDescription() != b.GetMarkdownDescription() {
return false
}
if a.IsRequired() != b.IsRequired() {
return false
}
if a.IsOptional() != b.IsOptional() {
return false
}
if a.IsComputed() != b.IsComputed() {
return false
}
if a.IsSensitive() != b.IsSensitive() {
return false
}
return true
}