Skip to content

Commit ea5dd66

Browse files
authored
all: Remove remaining Block-based MaxItems and MinItems functionality (#577)
Reference: #437 Block MaxItems and MinItems support, while defined in the Terraform protocol, is intentionially not included in the newer schema handling. Terraform can only perform limited static analysis of blocks and errors generated occur before the provider is called for configuration validation, which means that practitioners do not get all configuration errors at the same time. Provider developers can implement validators to achieve the same validation functionality, for example using the `listvalidator.Size*` and `setvalidator.Size*` validators in the terraform-plugin-framework-validators Go module.
1 parent 707c9ca commit ea5dd66

32 files changed

+7
-1169
lines changed

datasource/schema/list_nested_block.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,6 @@ func (b ListNestedBlock) GetMarkdownDescription() string {
158158
return b.MarkdownDescription
159159
}
160160

161-
// GetMaxItems always returns 0.
162-
//
163-
// Deprecated: This method will be removed in the future. Use validators
164-
// instead.
165-
func (b ListNestedBlock) GetMaxItems() int64 {
166-
return 0
167-
}
168-
169-
// GetMinItems always returns 0.
170-
//
171-
// Deprecated: This method will be removed in the future. Use validators
172-
// instead.
173-
func (b ListNestedBlock) GetMinItems() int64 {
174-
return 0
175-
}
176-
177161
// GetNestedObject returns the NestedObject field value.
178162
func (b ListNestedBlock) GetNestedObject() fwschema.NestedBlockObject {
179163
return b.NestedObject

datasource/schema/list_nested_block_test.go

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -297,74 +297,6 @@ func TestListNestedBlockGetMarkdownDescription(t *testing.T) {
297297
}
298298
}
299299

300-
func TestListNestedBlockGetMaxItems(t *testing.T) {
301-
t.Parallel()
302-
303-
testCases := map[string]struct {
304-
block schema.ListNestedBlock
305-
expected int64
306-
}{
307-
"0": {
308-
block: schema.ListNestedBlock{
309-
NestedObject: schema.NestedBlockObject{
310-
Attributes: map[string]schema.Attribute{
311-
"testattr": schema.StringAttribute{},
312-
},
313-
},
314-
},
315-
expected: 0,
316-
},
317-
}
318-
319-
for name, testCase := range testCases {
320-
name, testCase := name, testCase
321-
322-
t.Run(name, func(t *testing.T) {
323-
t.Parallel()
324-
325-
got := testCase.block.GetMaxItems()
326-
327-
if diff := cmp.Diff(got, testCase.expected); diff != "" {
328-
t.Errorf("unexpected difference: %s", diff)
329-
}
330-
})
331-
}
332-
}
333-
334-
func TestListNestedBlockGetMinItems(t *testing.T) {
335-
t.Parallel()
336-
337-
testCases := map[string]struct {
338-
block schema.ListNestedBlock
339-
expected int64
340-
}{
341-
"0": {
342-
block: schema.ListNestedBlock{
343-
NestedObject: schema.NestedBlockObject{
344-
Attributes: map[string]schema.Attribute{
345-
"testattr": schema.StringAttribute{},
346-
},
347-
},
348-
},
349-
expected: 0,
350-
},
351-
}
352-
353-
for name, testCase := range testCases {
354-
name, testCase := name, testCase
355-
356-
t.Run(name, func(t *testing.T) {
357-
t.Parallel()
358-
359-
got := testCase.block.GetMinItems()
360-
361-
if diff := cmp.Diff(got, testCase.expected); diff != "" {
362-
t.Errorf("unexpected difference: %s", diff)
363-
}
364-
})
365-
}
366-
}
367-
368300
func TestListNestedBlockGetNestedObject(t *testing.T) {
369301
t.Parallel()
370302

datasource/schema/set_nested_block.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,6 @@ func (b SetNestedBlock) GetMarkdownDescription() string {
158158
return b.MarkdownDescription
159159
}
160160

161-
// GetMaxItems always returns 0.
162-
//
163-
// Deprecated: This method will be removed in the future. Use validators
164-
// instead.
165-
func (b SetNestedBlock) GetMaxItems() int64 {
166-
return 0
167-
}
168-
169-
// GetMinItems always returns 0.
170-
//
171-
// Deprecated: This method will be removed in the future. Use validators
172-
// instead.
173-
func (b SetNestedBlock) GetMinItems() int64 {
174-
return 0
175-
}
176-
177161
// GetNestedObject returns the NestedObject field value.
178162
func (b SetNestedBlock) GetNestedObject() fwschema.NestedBlockObject {
179163
return b.NestedObject

datasource/schema/set_nested_block_test.go

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -297,74 +297,6 @@ func TestSetNestedBlockGetMarkdownDescription(t *testing.T) {
297297
}
298298
}
299299

300-
func TestSetNestedBlockGetMaxItems(t *testing.T) {
301-
t.Parallel()
302-
303-
testCases := map[string]struct {
304-
block schema.SetNestedBlock
305-
expected int64
306-
}{
307-
"0": {
308-
block: schema.SetNestedBlock{
309-
NestedObject: schema.NestedBlockObject{
310-
Attributes: map[string]schema.Attribute{
311-
"testattr": schema.StringAttribute{},
312-
},
313-
},
314-
},
315-
expected: 0,
316-
},
317-
}
318-
319-
for name, testCase := range testCases {
320-
name, testCase := name, testCase
321-
322-
t.Run(name, func(t *testing.T) {
323-
t.Parallel()
324-
325-
got := testCase.block.GetMaxItems()
326-
327-
if diff := cmp.Diff(got, testCase.expected); diff != "" {
328-
t.Errorf("unexpected difference: %s", diff)
329-
}
330-
})
331-
}
332-
}
333-
334-
func TestSetNestedBlockGetMinItems(t *testing.T) {
335-
t.Parallel()
336-
337-
testCases := map[string]struct {
338-
block schema.SetNestedBlock
339-
expected int64
340-
}{
341-
"0": {
342-
block: schema.SetNestedBlock{
343-
NestedObject: schema.NestedBlockObject{
344-
Attributes: map[string]schema.Attribute{
345-
"testattr": schema.StringAttribute{},
346-
},
347-
},
348-
},
349-
expected: 0,
350-
},
351-
}
352-
353-
for name, testCase := range testCases {
354-
name, testCase := name, testCase
355-
356-
t.Run(name, func(t *testing.T) {
357-
t.Parallel()
358-
359-
got := testCase.block.GetMinItems()
360-
361-
if diff := cmp.Diff(got, testCase.expected); diff != "" {
362-
t.Errorf("unexpected difference: %s", diff)
363-
}
364-
})
365-
}
366-
}
367-
368300
func TestSetNestedBlockGetNestedObject(t *testing.T) {
369301
t.Parallel()
370302

datasource/schema/single_nested_block.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,6 @@ func (b SingleNestedBlock) GetMarkdownDescription() string {
167167
return b.MarkdownDescription
168168
}
169169

170-
// GetMaxItems always returns 0.
171-
//
172-
// Deprecated: This method will be removed in the future.
173-
func (b SingleNestedBlock) GetMaxItems() int64 {
174-
return 0
175-
}
176-
177-
// GetMinItems always returns 0.
178-
//
179-
// Deprecated: This method will be removed in the future.
180-
func (b SingleNestedBlock) GetMinItems() int64 {
181-
return 0
182-
}
183-
184170
// GetNestedObject returns a generated NestedBlockObject from the
185171
// Attributes, CustomType, and Validators field values.
186172
func (b SingleNestedBlock) GetNestedObject() fwschema.NestedBlockObject {

datasource/schema/single_nested_block_test.go

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -297,70 +297,6 @@ func TestSingleNestedBlockGetMarkdownDescription(t *testing.T) {
297297
}
298298
}
299299

300-
func TestSingleNestedBlockGetMaxItems(t *testing.T) {
301-
t.Parallel()
302-
303-
testCases := map[string]struct {
304-
block schema.SingleNestedBlock
305-
expected int64
306-
}{
307-
"0": {
308-
block: schema.SingleNestedBlock{
309-
Attributes: map[string]schema.Attribute{
310-
"testattr": schema.StringAttribute{},
311-
},
312-
},
313-
expected: 0,
314-
},
315-
}
316-
317-
for name, testCase := range testCases {
318-
name, testCase := name, testCase
319-
320-
t.Run(name, func(t *testing.T) {
321-
t.Parallel()
322-
323-
got := testCase.block.GetMaxItems()
324-
325-
if diff := cmp.Diff(got, testCase.expected); diff != "" {
326-
t.Errorf("unexpected difference: %s", diff)
327-
}
328-
})
329-
}
330-
}
331-
332-
func TestSingleNestedBlockGetMinItems(t *testing.T) {
333-
t.Parallel()
334-
335-
testCases := map[string]struct {
336-
block schema.SingleNestedBlock
337-
expected int64
338-
}{
339-
"0": {
340-
block: schema.SingleNestedBlock{
341-
Attributes: map[string]schema.Attribute{
342-
"testattr": schema.StringAttribute{},
343-
},
344-
},
345-
expected: 0,
346-
},
347-
}
348-
349-
for name, testCase := range testCases {
350-
name, testCase := name, testCase
351-
352-
t.Run(name, func(t *testing.T) {
353-
t.Parallel()
354-
355-
got := testCase.block.GetMinItems()
356-
357-
if diff := cmp.Diff(got, testCase.expected); diff != "" {
358-
t.Errorf("unexpected difference: %s", diff)
359-
}
360-
})
361-
}
362-
}
363-
364300
func TestSingleNestedBlockGetNestedObject(t *testing.T) {
365301
t.Parallel()
366302

internal/fwschema/block.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import (
1313
// Refer to the internal/fwschema/fwxschema package for optional interfaces
1414
// that define framework-specific functionality, such a plan modification and
1515
// validation.
16+
//
17+
// Note that MaxItems and MinItems support, while defined in the Terraform
18+
// protocol, is intentially not present. Terraform can only perform limited
19+
// static analysis of blocks and errors generated occur before the provider
20+
// is called for configuration validation, which means that practitioners do
21+
// not get all configuration errors at the same time. Provider developers can
22+
// implement validators to achieve the same validation functionality.
1623
type Block interface {
1724
// Implementations should include the tftypes.AttributePathStepper
1825
// interface methods for proper path and data handling.
@@ -37,16 +44,6 @@ type Block interface {
3744
// name.
3845
GetMarkdownDescription() string
3946

40-
// GetMaxItems should return the max items of a block. This is named
41-
// differently than MaxItems to prevent a conflict with the tfsdk.Block
42-
// field name.
43-
GetMaxItems() int64
44-
45-
// GetMinItems should return the min items of a block. This is named
46-
// differently than MinItems to prevent a conflict with the tfsdk.Block
47-
// field name.
48-
GetMinItems() int64
49-
5047
// GetNestedObject should return the object underneath the block.
5148
// For single nesting mode, the NestedBlockObject can be generated from
5249
// the Block.
@@ -81,13 +78,5 @@ func BlocksEqual(a, b Block) bool {
8178
return false
8279
}
8380

84-
if a.GetMaxItems() != b.GetMaxItems() {
85-
return false
86-
}
87-
88-
if a.GetMinItems() != b.GetMinItems() {
89-
return false
90-
}
91-
9281
return true
9382
}

0 commit comments

Comments
 (0)