diff --git a/datasource/schema/list_nested_block.go b/datasource/schema/list_nested_block.go index 29fc172a0..30c5e7792 100644 --- a/datasource/schema/list_nested_block.go +++ b/datasource/schema/list_nested_block.go @@ -158,22 +158,6 @@ func (b ListNestedBlock) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems always returns 0. -// -// Deprecated: This method will be removed in the future. Use validators -// instead. -func (b ListNestedBlock) GetMaxItems() int64 { - return 0 -} - -// GetMinItems always returns 0. -// -// Deprecated: This method will be removed in the future. Use validators -// instead. -func (b ListNestedBlock) GetMinItems() int64 { - return 0 -} - // GetNestedObject returns the NestedObject field value. func (b ListNestedBlock) GetNestedObject() fwschema.NestedBlockObject { return b.NestedObject diff --git a/datasource/schema/list_nested_block_test.go b/datasource/schema/list_nested_block_test.go index 9bbcb5a6f..6d6e2350e 100644 --- a/datasource/schema/list_nested_block_test.go +++ b/datasource/schema/list_nested_block_test.go @@ -297,74 +297,6 @@ func TestListNestedBlockGetMarkdownDescription(t *testing.T) { } } -func TestListNestedBlockGetMaxItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.ListNestedBlock - expected int64 - }{ - "0": { - block: schema.ListNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMaxItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - -func TestListNestedBlockGetMinItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.ListNestedBlock - expected int64 - }{ - "0": { - block: schema.ListNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMinItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - func TestListNestedBlockGetNestedObject(t *testing.T) { t.Parallel() diff --git a/datasource/schema/set_nested_block.go b/datasource/schema/set_nested_block.go index 87d453f66..63992226d 100644 --- a/datasource/schema/set_nested_block.go +++ b/datasource/schema/set_nested_block.go @@ -158,22 +158,6 @@ func (b SetNestedBlock) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems always returns 0. -// -// Deprecated: This method will be removed in the future. Use validators -// instead. -func (b SetNestedBlock) GetMaxItems() int64 { - return 0 -} - -// GetMinItems always returns 0. -// -// Deprecated: This method will be removed in the future. Use validators -// instead. -func (b SetNestedBlock) GetMinItems() int64 { - return 0 -} - // GetNestedObject returns the NestedObject field value. func (b SetNestedBlock) GetNestedObject() fwschema.NestedBlockObject { return b.NestedObject diff --git a/datasource/schema/set_nested_block_test.go b/datasource/schema/set_nested_block_test.go index 7edbad858..b511effd7 100644 --- a/datasource/schema/set_nested_block_test.go +++ b/datasource/schema/set_nested_block_test.go @@ -297,74 +297,6 @@ func TestSetNestedBlockGetMarkdownDescription(t *testing.T) { } } -func TestSetNestedBlockGetMaxItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.SetNestedBlock - expected int64 - }{ - "0": { - block: schema.SetNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMaxItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - -func TestSetNestedBlockGetMinItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.SetNestedBlock - expected int64 - }{ - "0": { - block: schema.SetNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMinItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - func TestSetNestedBlockGetNestedObject(t *testing.T) { t.Parallel() diff --git a/datasource/schema/single_nested_block.go b/datasource/schema/single_nested_block.go index 3f082be2e..4a8b9734c 100644 --- a/datasource/schema/single_nested_block.go +++ b/datasource/schema/single_nested_block.go @@ -167,20 +167,6 @@ func (b SingleNestedBlock) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems always returns 0. -// -// Deprecated: This method will be removed in the future. -func (b SingleNestedBlock) GetMaxItems() int64 { - return 0 -} - -// GetMinItems always returns 0. -// -// Deprecated: This method will be removed in the future. -func (b SingleNestedBlock) GetMinItems() int64 { - return 0 -} - // GetNestedObject returns a generated NestedBlockObject from the // Attributes, CustomType, and Validators field values. func (b SingleNestedBlock) GetNestedObject() fwschema.NestedBlockObject { diff --git a/datasource/schema/single_nested_block_test.go b/datasource/schema/single_nested_block_test.go index ce4654543..5f3255328 100644 --- a/datasource/schema/single_nested_block_test.go +++ b/datasource/schema/single_nested_block_test.go @@ -297,70 +297,6 @@ func TestSingleNestedBlockGetMarkdownDescription(t *testing.T) { } } -func TestSingleNestedBlockGetMaxItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.SingleNestedBlock - expected int64 - }{ - "0": { - block: schema.SingleNestedBlock{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMaxItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - -func TestSingleNestedBlockGetMinItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.SingleNestedBlock - expected int64 - }{ - "0": { - block: schema.SingleNestedBlock{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMinItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - func TestSingleNestedBlockGetNestedObject(t *testing.T) { t.Parallel() diff --git a/internal/fwschema/block.go b/internal/fwschema/block.go index 6f465a23b..919264cd1 100644 --- a/internal/fwschema/block.go +++ b/internal/fwschema/block.go @@ -13,6 +13,13 @@ import ( // Refer to the internal/fwschema/fwxschema package for optional interfaces // that define framework-specific functionality, such a plan modification and // validation. +// +// Note that MaxItems and MinItems support, while defined in the Terraform +// protocol, is intentially not present. 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. type Block interface { // Implementations should include the tftypes.AttributePathStepper // interface methods for proper path and data handling. @@ -37,16 +44,6 @@ type Block interface { // 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. @@ -81,13 +78,5 @@ func BlocksEqual(a, b Block) bool { return false } - if a.GetMaxItems() != b.GetMaxItems() { - return false - } - - if a.GetMinItems() != b.GetMinItems() { - return false - } - return true } diff --git a/internal/fwserver/block_validation.go b/internal/fwserver/block_validation.go index 6b5b6314e..25eb96501 100644 --- a/internal/fwserver/block_validation.go +++ b/internal/fwserver/block_validation.go @@ -3,14 +3,11 @@ package fwserver import ( "context" "fmt" - "strings" - "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/fwschema" "github.com/hashicorp/terraform-plugin-framework/internal/fwschema/fwxschema" "github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata" "github.com/hashicorp/terraform-plugin-framework/internal/logging" - "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" ) @@ -84,29 +81,6 @@ func BlockValidate(ctx context.Context, b fwschema.Block, req ValidateAttributeR resp.Diagnostics.Append(nestedBlockObjectResp.Diagnostics...) } - - // Terraform 0.12 through 0.15.1 do not implement block MaxItems - // validation. - // - // Terraform 0.15.2 and later implements MaxItems validation during - // configuration decoding, so if this framework drops Terraform support - // for earlier versions, this validation can be removed. - if b.GetMaxItems() > 0 && int64(len(l.Elements())) > b.GetMaxItems() { - resp.Diagnostics.Append(blockMaxItemsDiagnostic(req.AttributePath, b.GetMaxItems(), len(l.Elements()))) - } - - // Terraform 0.12 through 0.15.1 implement conservative block MinItems - // validation, where the MinItems can be reset to 1 in certain - // situations. This validation must ensure the list itself is not - // unknown, which could erroneously trigger the error since the list - // would have 0 elements. - // - // Terraform 0.15.2 and later implements proper MinItems validation - // during configuration decoding, so if this framework drops Terraform - // support for earlier versions, this validation can be removed. - if b.GetMinItems() > 0 && int64(len(l.Elements())) < b.GetMinItems() && !l.IsUnknown() { - resp.Diagnostics.Append(blockMinItemsDiagnostic(req.AttributePath, b.GetMinItems(), len(l.Elements()))) - } case fwschema.BlockNestingModeSet: setVal, ok := req.AttributeConfig.(basetypes.SetValuable) @@ -141,29 +115,6 @@ func BlockValidate(ctx context.Context, b fwschema.Block, req ValidateAttributeR resp.Diagnostics.Append(nestedBlockObjectResp.Diagnostics...) } - - // Terraform 0.12 through 0.15.1 do not implement block MaxItems - // validation. - // - // Terraform 0.15.2 and later implements MaxItems validation during - // configuration decoding, so if this framework drops Terraform support - // for earlier versions, this validation can be removed. - if b.GetMaxItems() > 0 && int64(len(s.Elements())) > b.GetMaxItems() { - resp.Diagnostics.Append(blockMaxItemsDiagnostic(req.AttributePath, b.GetMaxItems(), len(s.Elements()))) - } - - // Terraform 0.12 through 0.15.1 implement conservative block MinItems - // validation, where the MinItems can be reset to 1 in certain - // situations. This validation must ensure the set itself is not - // unknown, which could erroneously trigger the error since the set - // would have 0 elements. - // - // Terraform 0.15.2 and later implements proper MinItems validation - // during configuration decoding, so if this framework drops Terraform - // support for earlier versions, this validation can be removed. - if b.GetMinItems() > 0 && int64(len(s.Elements())) < b.GetMinItems() && !s.IsUnknown() { - resp.Diagnostics.Append(blockMinItemsDiagnostic(req.AttributePath, b.GetMinItems(), len(s.Elements()))) - } case fwschema.BlockNestingModeSingle: objectVal, ok := req.AttributeConfig.(basetypes.ObjectValuable) @@ -196,10 +147,6 @@ func BlockValidate(ctx context.Context, b fwschema.Block, req ValidateAttributeR NestedBlockObjectValidate(ctx, nestedBlockObject, nestedBlockObjectReq, nestedBlockObjectResp) resp.Diagnostics.Append(nestedBlockObjectResp.Diagnostics...) - - if b.GetMinItems() == 1 && o.IsNull() { - resp.Diagnostics.Append(blockMinItemsDiagnostic(req.AttributePath, b.GetMinItems(), 0)) - } default: err := fmt.Errorf("unknown block validation nesting mode (%T: %v) at path: %s", nm, nm, req.AttributePath) resp.Diagnostics.AddAttributeError( @@ -504,53 +451,3 @@ func NestedBlockObjectValidate(ctx context.Context, o fwschema.NestedBlockObject resp.Diagnostics.Append(nestedBlockResp.Diagnostics...) } } - -func blockMaxItemsDiagnostic(attrPath path.Path, maxItems int64, elements int) diag.Diagnostic { - var details strings.Builder - - details.WriteString("The configuration should declare a maximum of ") - - if maxItems == 1 { - details.WriteString("1 block") - } else { - details.WriteString(fmt.Sprintf("%d blocks", maxItems)) - } - - // Elements will always be greater than 1, so do not need to handle the - // singular case. - details.WriteString(fmt.Sprintf(", however %d blocks were configured.", elements)) - - return diag.NewAttributeErrorDiagnostic( - attrPath, - "Extra Block Configuration", - details.String(), - ) -} - -func blockMinItemsDiagnostic(attrPath path.Path, minItems int64, elements int) diag.Diagnostic { - var details strings.Builder - - details.WriteString("The configuration should declare a minimum of ") - - if minItems == 1 { - details.WriteString("1 block") - } else { - details.WriteString(fmt.Sprintf("%d blocks", minItems)) - } - - details.WriteString(", however ") - - if elements == 1 { - details.WriteString("1 block was") - } else { - details.WriteString(fmt.Sprintf("%d blocks were", elements)) - } - - details.WriteString(" configured.") - - return diag.NewAttributeErrorDiagnostic( - attrPath, - "Missing Block Configuration", - details.String(), - ) -} diff --git a/internal/fwserver/block_validation_test.go b/internal/fwserver/block_validation_test.go index cacded194..3290d261c 100644 --- a/internal/fwserver/block_validation_test.go +++ b/internal/fwserver/block_validation_test.go @@ -2262,105 +2262,3 @@ func TestNestedBlockObjectValidateObject(t *testing.T) { }) } } - -func TestBlockMaxItemsDiagnostic(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - path path.Path - maxItems int64 - elements int - expected diag.Diagnostic - }{ - "1-maxitems-2-elements": { - path: path.Root("test"), - maxItems: 1, - elements: 2, - expected: diag.NewAttributeErrorDiagnostic( - path.Root("test"), - "Extra Block Configuration", - "The configuration should declare a maximum of 1 block, however 2 blocks were configured.", - ), - }, - "2-maxitems-3-elements": { - path: path.Root("test"), - maxItems: 2, - elements: 3, - expected: diag.NewAttributeErrorDiagnostic( - path.Root("test"), - "Extra Block Configuration", - "The configuration should declare a maximum of 2 blocks, however 3 blocks were configured.", - ), - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := blockMaxItemsDiagnostic(testCase.path, testCase.maxItems, testCase.elements) - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - -func TestBlockMinItemsDiagnostic(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - path path.Path - minItems int64 - elements int - expected diag.Diagnostic - }{ - "1-minitems-0-elements": { - path: path.Root("test"), - minItems: 1, - elements: 0, - expected: diag.NewAttributeErrorDiagnostic( - path.Root("test"), - "Missing Block Configuration", - "The configuration should declare a minimum of 1 block, however 0 blocks were configured.", - ), - }, - "2-minitems-1-element": { - path: path.Root("test"), - minItems: 2, - elements: 1, - expected: diag.NewAttributeErrorDiagnostic( - path.Root("test"), - "Missing Block Configuration", - "The configuration should declare a minimum of 2 blocks, however 1 block was configured.", - ), - }, - "3-minitems-2-elements": { - path: path.Root("test"), - minItems: 3, - elements: 2, - expected: diag.NewAttributeErrorDiagnostic( - path.Root("test"), - "Missing Block Configuration", - "The configuration should declare a minimum of 3 blocks, however 2 blocks were configured.", - ), - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := blockMinItemsDiagnostic(testCase.path, testCase.minItems, testCase.elements) - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} diff --git a/internal/testing/testschema/block.go b/internal/testing/testschema/block.go index 74cc40731..6123f194e 100644 --- a/internal/testing/testschema/block.go +++ b/internal/testing/testschema/block.go @@ -13,8 +13,6 @@ type Block struct { DeprecationMessage string Description string MarkdownDescription string - MaxItems int64 - MinItems int64 NestedObject fwschema.NestedBlockObject NestingMode fwschema.BlockNestingMode } @@ -50,16 +48,6 @@ func (b Block) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems satisfies the fwschema.Block interface. -func (b Block) GetMaxItems() int64 { - return b.MaxItems -} - -// GetMinItems satisfies the fwschema.Block interface. -func (b Block) GetMinItems() int64 { - return b.MinItems -} - // GetNestedObject satisfies the fwschema.Block interface. func (b Block) GetNestedObject() fwschema.NestedBlockObject { return b.NestedObject diff --git a/internal/testing/testschema/blockwithlistplanmodifiers.go b/internal/testing/testschema/blockwithlistplanmodifiers.go index 1a8fe08e6..1d293af87 100644 --- a/internal/testing/testschema/blockwithlistplanmodifiers.go +++ b/internal/testing/testschema/blockwithlistplanmodifiers.go @@ -17,8 +17,6 @@ type BlockWithListPlanModifiers struct { DeprecationMessage string Description string MarkdownDescription string - MaxItems int64 - MinItems int64 PlanModifiers []planmodifier.List } @@ -53,16 +51,6 @@ func (b BlockWithListPlanModifiers) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems satisfies the fwschema.Block interface. -func (b BlockWithListPlanModifiers) GetMaxItems() int64 { - return b.MaxItems -} - -// GetMinItems satisfies the fwschema.Block interface. -func (b BlockWithListPlanModifiers) GetMinItems() int64 { - return b.MinItems -} - // GetNestedObject satisfies the fwschema.Block interface. func (b BlockWithListPlanModifiers) GetNestedObject() fwschema.NestedBlockObject { return NestedBlockObject{ diff --git a/internal/testing/testschema/blockwithlistvalidators.go b/internal/testing/testschema/blockwithlistvalidators.go index b236d7ed0..47f587bfb 100644 --- a/internal/testing/testschema/blockwithlistvalidators.go +++ b/internal/testing/testschema/blockwithlistvalidators.go @@ -17,8 +17,6 @@ type BlockWithListValidators struct { DeprecationMessage string Description string MarkdownDescription string - MaxItems int64 - MinItems int64 Validators []validator.List } @@ -53,16 +51,6 @@ func (b BlockWithListValidators) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems satisfies the fwschema.Block interface. -func (b BlockWithListValidators) GetMaxItems() int64 { - return b.MaxItems -} - -// GetMinItems satisfies the fwschema.Block interface. -func (b BlockWithListValidators) GetMinItems() int64 { - return b.MinItems -} - // GetNestedObject satisfies the fwschema.Block interface. func (b BlockWithListValidators) GetNestedObject() fwschema.NestedBlockObject { return NestedBlockObject{ diff --git a/internal/testing/testschema/blockwithobjectplanmodifiers.go b/internal/testing/testschema/blockwithobjectplanmodifiers.go index 27f9a21e8..5375e6fb0 100644 --- a/internal/testing/testschema/blockwithobjectplanmodifiers.go +++ b/internal/testing/testschema/blockwithobjectplanmodifiers.go @@ -16,8 +16,6 @@ type BlockWithObjectPlanModifiers struct { DeprecationMessage string Description string MarkdownDescription string - MaxItems int64 - MinItems int64 PlanModifiers []planmodifier.Object } @@ -52,16 +50,6 @@ func (b BlockWithObjectPlanModifiers) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems satisfies the fwschema.Block interface. -func (b BlockWithObjectPlanModifiers) GetMaxItems() int64 { - return b.MaxItems -} - -// GetMinItems satisfies the fwschema.Block interface. -func (b BlockWithObjectPlanModifiers) GetMinItems() int64 { - return b.MinItems -} - // GetNestedObject satisfies the fwschema.Block interface. func (b BlockWithObjectPlanModifiers) GetNestedObject() fwschema.NestedBlockObject { return NestedBlockObjectWithPlanModifiers{ diff --git a/internal/testing/testschema/blockwithobjectvalidators.go b/internal/testing/testschema/blockwithobjectvalidators.go index 308c87172..7227df2ee 100644 --- a/internal/testing/testschema/blockwithobjectvalidators.go +++ b/internal/testing/testschema/blockwithobjectvalidators.go @@ -16,8 +16,6 @@ type BlockWithObjectValidators struct { DeprecationMessage string Description string MarkdownDescription string - MaxItems int64 - MinItems int64 Validators []validator.Object } @@ -52,16 +50,6 @@ func (b BlockWithObjectValidators) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems satisfies the fwschema.Block interface. -func (b BlockWithObjectValidators) GetMaxItems() int64 { - return b.MaxItems -} - -// GetMinItems satisfies the fwschema.Block interface. -func (b BlockWithObjectValidators) GetMinItems() int64 { - return b.MinItems -} - // GetNestedObject satisfies the fwschema.Block interface. func (b BlockWithObjectValidators) GetNestedObject() fwschema.NestedBlockObject { return NestedBlockObjectWithValidators{ diff --git a/internal/testing/testschema/blockwithsetplanmodifiers.go b/internal/testing/testschema/blockwithsetplanmodifiers.go index b0f080dfa..bb77e0a3b 100644 --- a/internal/testing/testschema/blockwithsetplanmodifiers.go +++ b/internal/testing/testschema/blockwithsetplanmodifiers.go @@ -17,8 +17,6 @@ type BlockWithSetPlanModifiers struct { DeprecationMessage string Description string MarkdownDescription string - MaxItems int64 - MinItems int64 PlanModifiers []planmodifier.Set } @@ -53,16 +51,6 @@ func (b BlockWithSetPlanModifiers) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems satisfies the fwschema.Block interface. -func (b BlockWithSetPlanModifiers) GetMaxItems() int64 { - return b.MaxItems -} - -// GetMinItems satisfies the fwschema.Block interface. -func (b BlockWithSetPlanModifiers) GetMinItems() int64 { - return b.MinItems -} - // GetNestedObject satisfies the fwschema.Block interface. func (b BlockWithSetPlanModifiers) GetNestedObject() fwschema.NestedBlockObject { return NestedBlockObject{ diff --git a/internal/testing/testschema/blockwithsetvalidators.go b/internal/testing/testschema/blockwithsetvalidators.go index b4743b3d4..6e58f84f7 100644 --- a/internal/testing/testschema/blockwithsetvalidators.go +++ b/internal/testing/testschema/blockwithsetvalidators.go @@ -17,8 +17,6 @@ type BlockWithSetValidators struct { DeprecationMessage string Description string MarkdownDescription string - MaxItems int64 - MinItems int64 Validators []validator.Set } @@ -53,16 +51,6 @@ func (b BlockWithSetValidators) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems satisfies the fwschema.Block interface. -func (b BlockWithSetValidators) GetMaxItems() int64 { - return b.MaxItems -} - -// GetMinItems satisfies the fwschema.Block interface. -func (b BlockWithSetValidators) GetMinItems() int64 { - return b.MinItems -} - // GetNestedObject satisfies the fwschema.Block interface. func (b BlockWithSetValidators) GetNestedObject() fwschema.NestedBlockObject { return NestedBlockObject{ diff --git a/internal/toproto5/block.go b/internal/toproto5/block.go index e35e4816c..18d380bb8 100644 --- a/internal/toproto5/block.go +++ b/internal/toproto5/block.go @@ -17,8 +17,6 @@ func Block(ctx context.Context, name string, path *tftypes.AttributePath, b fwsc Block: &tfprotov5.SchemaBlock{ Deprecated: b.GetDeprecationMessage() != "", }, - MinItems: b.GetMinItems(), - MaxItems: b.GetMaxItems(), TypeName: name, } diff --git a/internal/toproto5/block_test.go b/internal/toproto5/block_test.go index 2ff64546b..84832ba22 100644 --- a/internal/toproto5/block_test.go +++ b/internal/toproto5/block_test.go @@ -545,66 +545,6 @@ func TestBlock(t *testing.T) { TypeName: "test", }, }, - "maxitems": { - name: "test", - block: testschema.Block{ - NestedObject: testschema.NestedBlockObject{ - Attributes: map[string]fwschema.Attribute{ - "sub_test": testschema.Attribute{ - Type: types.StringType, - Optional: true, - }, - }, - }, - MaxItems: 10, - NestingMode: fwschema.BlockNestingModeList, - }, - path: tftypes.NewAttributePath(), - expected: &tfprotov5.SchemaNestedBlock{ - Block: &tfprotov5.SchemaBlock{ - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "sub_test", - Optional: true, - Type: tftypes.String, - }, - }, - }, - MaxItems: 10, - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - TypeName: "test", - }, - }, - "minitems": { - name: "test", - block: testschema.Block{ - NestedObject: testschema.NestedBlockObject{ - Attributes: map[string]fwschema.Attribute{ - "sub_test": testschema.Attribute{ - Type: types.StringType, - Optional: true, - }, - }, - }, - MinItems: 10, - NestingMode: fwschema.BlockNestingModeList, - }, - path: tftypes.NewAttributePath(), - expected: &tfprotov5.SchemaNestedBlock{ - Block: &tfprotov5.SchemaBlock{ - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "sub_test", - Optional: true, - Type: tftypes.String, - }, - }, - }, - MinItems: 10, - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - TypeName: "test", - }, - }, } for name, tc := range tests { diff --git a/internal/toproto6/block.go b/internal/toproto6/block.go index 0909dede0..3da25a200 100644 --- a/internal/toproto6/block.go +++ b/internal/toproto6/block.go @@ -17,8 +17,6 @@ func Block(ctx context.Context, name string, path *tftypes.AttributePath, b fwsc Block: &tfprotov6.SchemaBlock{ Deprecated: b.GetDeprecationMessage() != "", }, - MinItems: b.GetMinItems(), - MaxItems: b.GetMaxItems(), TypeName: name, } diff --git a/internal/toproto6/block_test.go b/internal/toproto6/block_test.go index 91d4ecdce..0568f5d26 100644 --- a/internal/toproto6/block_test.go +++ b/internal/toproto6/block_test.go @@ -545,66 +545,6 @@ func TestBlock(t *testing.T) { TypeName: "test", }, }, - "maxitems": { - name: "test", - block: testschema.Block{ - NestedObject: testschema.NestedBlockObject{ - Attributes: map[string]fwschema.Attribute{ - "sub_test": testschema.Attribute{ - Type: types.StringType, - Optional: true, - }, - }, - }, - MaxItems: 10, - NestingMode: fwschema.BlockNestingModeList, - }, - path: tftypes.NewAttributePath(), - expected: &tfprotov6.SchemaNestedBlock{ - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "sub_test", - Optional: true, - Type: tftypes.String, - }, - }, - }, - MaxItems: 10, - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - TypeName: "test", - }, - }, - "minitems": { - name: "test", - block: testschema.Block{ - NestedObject: testschema.NestedBlockObject{ - Attributes: map[string]fwschema.Attribute{ - "sub_test": testschema.Attribute{ - Type: types.StringType, - Optional: true, - }, - }, - }, - MinItems: 10, - NestingMode: fwschema.BlockNestingModeList, - }, - path: tftypes.NewAttributePath(), - expected: &tfprotov6.SchemaNestedBlock{ - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "sub_test", - Optional: true, - Type: tftypes.String, - }, - }, - }, - MinItems: 10, - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - TypeName: "test", - }, - }, } for name, tc := range tests { diff --git a/provider/schema/list_nested_block.go b/provider/schema/list_nested_block.go index 29fc172a0..30c5e7792 100644 --- a/provider/schema/list_nested_block.go +++ b/provider/schema/list_nested_block.go @@ -158,22 +158,6 @@ func (b ListNestedBlock) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems always returns 0. -// -// Deprecated: This method will be removed in the future. Use validators -// instead. -func (b ListNestedBlock) GetMaxItems() int64 { - return 0 -} - -// GetMinItems always returns 0. -// -// Deprecated: This method will be removed in the future. Use validators -// instead. -func (b ListNestedBlock) GetMinItems() int64 { - return 0 -} - // GetNestedObject returns the NestedObject field value. func (b ListNestedBlock) GetNestedObject() fwschema.NestedBlockObject { return b.NestedObject diff --git a/provider/schema/list_nested_block_test.go b/provider/schema/list_nested_block_test.go index 5d01f8a9e..3fa3cdb00 100644 --- a/provider/schema/list_nested_block_test.go +++ b/provider/schema/list_nested_block_test.go @@ -297,74 +297,6 @@ func TestListNestedBlockGetMarkdownDescription(t *testing.T) { } } -func TestListNestedBlockGetMaxItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.ListNestedBlock - expected int64 - }{ - "0": { - block: schema.ListNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMaxItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - -func TestListNestedBlockGetMinItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.ListNestedBlock - expected int64 - }{ - "0": { - block: schema.ListNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMinItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - func TestListNestedBlockGetNestedObject(t *testing.T) { t.Parallel() diff --git a/provider/schema/set_nested_block.go b/provider/schema/set_nested_block.go index 87d453f66..63992226d 100644 --- a/provider/schema/set_nested_block.go +++ b/provider/schema/set_nested_block.go @@ -158,22 +158,6 @@ func (b SetNestedBlock) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems always returns 0. -// -// Deprecated: This method will be removed in the future. Use validators -// instead. -func (b SetNestedBlock) GetMaxItems() int64 { - return 0 -} - -// GetMinItems always returns 0. -// -// Deprecated: This method will be removed in the future. Use validators -// instead. -func (b SetNestedBlock) GetMinItems() int64 { - return 0 -} - // GetNestedObject returns the NestedObject field value. func (b SetNestedBlock) GetNestedObject() fwschema.NestedBlockObject { return b.NestedObject diff --git a/provider/schema/set_nested_block_test.go b/provider/schema/set_nested_block_test.go index 54871da83..6e80b68e1 100644 --- a/provider/schema/set_nested_block_test.go +++ b/provider/schema/set_nested_block_test.go @@ -297,74 +297,6 @@ func TestSetNestedBlockGetMarkdownDescription(t *testing.T) { } } -func TestSetNestedBlockGetMaxItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.SetNestedBlock - expected int64 - }{ - "0": { - block: schema.SetNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMaxItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - -func TestSetNestedBlockGetMinItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.SetNestedBlock - expected int64 - }{ - "0": { - block: schema.SetNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMinItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - func TestSetNestedBlockGetNestedObject(t *testing.T) { t.Parallel() diff --git a/provider/schema/single_nested_block.go b/provider/schema/single_nested_block.go index 3f082be2e..4a8b9734c 100644 --- a/provider/schema/single_nested_block.go +++ b/provider/schema/single_nested_block.go @@ -167,20 +167,6 @@ func (b SingleNestedBlock) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems always returns 0. -// -// Deprecated: This method will be removed in the future. -func (b SingleNestedBlock) GetMaxItems() int64 { - return 0 -} - -// GetMinItems always returns 0. -// -// Deprecated: This method will be removed in the future. -func (b SingleNestedBlock) GetMinItems() int64 { - return 0 -} - // GetNestedObject returns a generated NestedBlockObject from the // Attributes, CustomType, and Validators field values. func (b SingleNestedBlock) GetNestedObject() fwschema.NestedBlockObject { diff --git a/provider/schema/single_nested_block_test.go b/provider/schema/single_nested_block_test.go index cecedaa0c..9079dd5b3 100644 --- a/provider/schema/single_nested_block_test.go +++ b/provider/schema/single_nested_block_test.go @@ -297,70 +297,6 @@ func TestSingleNestedBlockGetMarkdownDescription(t *testing.T) { } } -func TestSingleNestedBlockGetMaxItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.SingleNestedBlock - expected int64 - }{ - "0": { - block: schema.SingleNestedBlock{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMaxItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - -func TestSingleNestedBlockGetMinItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.SingleNestedBlock - expected int64 - }{ - "0": { - block: schema.SingleNestedBlock{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMinItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - func TestSingleNestedBlockGetNestedObject(t *testing.T) { t.Parallel() diff --git a/resource/schema/list_nested_block.go b/resource/schema/list_nested_block.go index 16aef6ec1..15896ae03 100644 --- a/resource/schema/list_nested_block.go +++ b/resource/schema/list_nested_block.go @@ -177,22 +177,6 @@ func (b ListNestedBlock) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems always returns 0. -// -// Deprecated: This method will be removed in the future. Use validators -// instead. -func (b ListNestedBlock) GetMaxItems() int64 { - return 0 -} - -// GetMinItems always returns 0. -// -// Deprecated: This method will be removed in the future. Use validators -// instead. -func (b ListNestedBlock) GetMinItems() int64 { - return 0 -} - // GetNestedObject returns the NestedObject field value. func (b ListNestedBlock) GetNestedObject() fwschema.NestedBlockObject { return b.NestedObject diff --git a/resource/schema/list_nested_block_test.go b/resource/schema/list_nested_block_test.go index 964d18363..8f4bd7c65 100644 --- a/resource/schema/list_nested_block_test.go +++ b/resource/schema/list_nested_block_test.go @@ -298,74 +298,6 @@ func TestListNestedBlockGetMarkdownDescription(t *testing.T) { } } -func TestListNestedBlockGetMaxItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.ListNestedBlock - expected int64 - }{ - "0": { - block: schema.ListNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMaxItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - -func TestListNestedBlockGetMinItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.ListNestedBlock - expected int64 - }{ - "0": { - block: schema.ListNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMinItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - func TestListNestedBlockGetNestedObject(t *testing.T) { t.Parallel() diff --git a/resource/schema/set_nested_block.go b/resource/schema/set_nested_block.go index 3b99a73c2..cde1bbc11 100644 --- a/resource/schema/set_nested_block.go +++ b/resource/schema/set_nested_block.go @@ -177,22 +177,6 @@ func (b SetNestedBlock) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems always returns 0. -// -// Deprecated: This method will be removed in the future. Use validators -// instead. -func (b SetNestedBlock) GetMaxItems() int64 { - return 0 -} - -// GetMinItems always returns 0. -// -// Deprecated: This method will be removed in the future. Use validators -// instead. -func (b SetNestedBlock) GetMinItems() int64 { - return 0 -} - // GetNestedObject returns the NestedObject field value. func (b SetNestedBlock) GetNestedObject() fwschema.NestedBlockObject { return b.NestedObject diff --git a/resource/schema/set_nested_block_test.go b/resource/schema/set_nested_block_test.go index 71f3ae6b3..3dc143076 100644 --- a/resource/schema/set_nested_block_test.go +++ b/resource/schema/set_nested_block_test.go @@ -298,74 +298,6 @@ func TestSetNestedBlockGetMarkdownDescription(t *testing.T) { } } -func TestSetNestedBlockGetMaxItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.SetNestedBlock - expected int64 - }{ - "0": { - block: schema.SetNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMaxItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - -func TestSetNestedBlockGetMinItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.SetNestedBlock - expected int64 - }{ - "0": { - block: schema.SetNestedBlock{ - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMinItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - func TestSetNestedBlockGetNestedObject(t *testing.T) { t.Parallel() diff --git a/resource/schema/single_nested_block.go b/resource/schema/single_nested_block.go index 1b62c9f06..3f2ac51ec 100644 --- a/resource/schema/single_nested_block.go +++ b/resource/schema/single_nested_block.go @@ -186,20 +186,6 @@ func (b SingleNestedBlock) GetMarkdownDescription() string { return b.MarkdownDescription } -// GetMaxItems always returns 0. -// -// Deprecated: This method will be removed in the future. -func (b SingleNestedBlock) GetMaxItems() int64 { - return 0 -} - -// GetMinItems always returns 0. -// -// Deprecated: This method will be removed in the future. -func (b SingleNestedBlock) GetMinItems() int64 { - return 0 -} - // GetNestedObject returns a generated NestedBlockObject from the // Attributes, CustomType, and Validators field values. func (b SingleNestedBlock) GetNestedObject() fwschema.NestedBlockObject { diff --git a/resource/schema/single_nested_block_test.go b/resource/schema/single_nested_block_test.go index 7cf0eb82b..5b1e3a7b8 100644 --- a/resource/schema/single_nested_block_test.go +++ b/resource/schema/single_nested_block_test.go @@ -298,70 +298,6 @@ func TestSingleNestedBlockGetMarkdownDescription(t *testing.T) { } } -func TestSingleNestedBlockGetMaxItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.SingleNestedBlock - expected int64 - }{ - "0": { - block: schema.SingleNestedBlock{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMaxItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - -func TestSingleNestedBlockGetMinItems(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - block schema.SingleNestedBlock - expected int64 - }{ - "0": { - block: schema.SingleNestedBlock{ - Attributes: map[string]schema.Attribute{ - "testattr": schema.StringAttribute{}, - }, - }, - expected: 0, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - got := testCase.block.GetMinItems() - - if diff := cmp.Diff(got, testCase.expected); diff != "" { - t.Errorf("unexpected difference: %s", diff) - } - }) - } -} - func TestSingleNestedBlockGetNestedObject(t *testing.T) { t.Parallel()