-
Notifications
You must be signed in to change notification settings - Fork 91
/
block.go
93 lines (75 loc) · 3 KB
/
block.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
package fwschema
import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
// Block is the core interface required for implementing Terraform schema
// functionality that structurally holds attributes and blocks. This is
// intended to be the first abstraction of tfsdk.Block 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 Block interface {
// Implementations should include the tftypes.AttributePathStepper
// interface methods for proper path and data handling.
tftypes.AttributePathStepper
// Equal should return true if the other block is exactly equivalent.
Equal(o Block) bool
// 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
// GetMaxItems should return the max items of a block. This is named
// differently than MaxItems to prevent a conflict with the tfsdk.Block
// field name.
GetMaxItems() int64
// GetMinItems should return the min items of a block. This is named
// differently than MinItems to prevent a conflict with the tfsdk.Block
// field name.
GetMinItems() int64
// GetNestedObject should return the object underneath the block.
// For single nesting mode, the NestedBlockObject can be generated from
// the Block.
GetNestedObject() NestedBlockObject
// GetNestingMode should return the nesting mode of a block. This is named
// differently than NestingMode to prevent a conflict with the tfsdk.Block
// field name.
GetNestingMode() BlockNestingMode
// Type should return the framework type of a block.
Type() attr.Type
}
// BlocksEqual is a helper function to perform equality testing on two
// Block. Attribute Equal implementations should still compare the concrete
// types in addition to using this helper.
func BlocksEqual(a, b Block) bool {
if !a.Type().Equal(b.Type()) {
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.GetMaxItems() != b.GetMaxItems() {
return false
}
if a.GetMinItems() != b.GetMinItems() {
return false
}
return true
}