From 7a01a5a64e246d1e533271888c828fe28d2f64f0 Mon Sep 17 00:00:00 2001 From: k-yomo Date: Sun, 18 Dec 2022 23:15:21 +0900 Subject: [PATCH 1/4] Ignore MinItems and MaxItems diff in nested block --- tf5muxserver/mux_server_test.go | 48 +++++++++++++++++++++++++++++++++ tf5muxserver/schema_equality.go | 1 + 2 files changed, 49 insertions(+) diff --git a/tf5muxserver/mux_server_test.go b/tf5muxserver/mux_server_test.go index b568464..9b7ceb2 100644 --- a/tf5muxserver/mux_server_test.go +++ b/tf5muxserver/mux_server_test.go @@ -547,6 +547,54 @@ func TestNewMuxServer(t *testing.T) { }).ProviderServer, }, }, + "nested block MinItems and MaxItems diff are ignored": { + servers: []func() tfprotov5.ProviderServer{ + (&tf5testserver.TestServer{ + ProviderSchema: &tfprotov5.Schema{ + Version: 1, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{}, + }, + MinItems: 1, + MaxItems: 2, + }, + }, + }, + }, + }).ProviderServer, + (&tf5testserver.TestServer{ + ProviderSchema: &tfprotov5.Schema{ + Version: 1, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{}, + }, + MinItems: 0, + MaxItems: 0, + }, + }, + }, + }, + }).ProviderServer, + }, + }, } for name, testCase := range testCases { diff --git a/tf5muxserver/schema_equality.go b/tf5muxserver/schema_equality.go index acaae7d..78c4f22 100644 --- a/tf5muxserver/schema_equality.go +++ b/tf5muxserver/schema_equality.go @@ -15,6 +15,7 @@ var schemaCmpOptions = []cmp.Option{ cmpopts.SortSlices(func(i, j *tfprotov5.SchemaNestedBlock) bool { return i.TypeName < j.TypeName }), + cmpopts.IgnoreFields(tfprotov5.SchemaNestedBlock{}, "MinItems", "MaxItems"), } // schemaDiff outputs the difference between schemas while accounting for From ec8ad3450894f2956f5656e37bdcbbc67573dafa Mon Sep 17 00:00:00 2001 From: k-yomo Date: Tue, 20 Dec 2022 16:55:06 +0900 Subject: [PATCH 2/4] Ignore MinItems and MaxItems diff in nested block in tf6 mux server --- tf6muxserver/mux_server_test.go | 48 +++++++++++++++++++++++++++++++++ tf6muxserver/schema_equality.go | 1 + 2 files changed, 49 insertions(+) diff --git a/tf6muxserver/mux_server_test.go b/tf6muxserver/mux_server_test.go index 8dad4ad..abc1b05 100644 --- a/tf6muxserver/mux_server_test.go +++ b/tf6muxserver/mux_server_test.go @@ -547,6 +547,54 @@ func TestNewMuxServer(t *testing.T) { }).ProviderServer, }, }, + "nested block MinItems and MaxItems diff are ignored": { + servers: []func() tfprotov6.ProviderServer{ + (&tf6testserver.TestServer{ + ProviderSchema: &tfprotov6.Schema{ + Version: 1, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{}, + }, + MinItems: 1, + MaxItems: 2, + }, + }, + }, + }, + }).ProviderServer, + (&tf6testserver.TestServer{ + ProviderSchema: &tfprotov6.Schema{ + Version: 1, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{}, + }, + MinItems: 0, + MaxItems: 0, + }, + }, + }, + }, + }).ProviderServer, + }, + }, } for name, testCase := range testCases { diff --git a/tf6muxserver/schema_equality.go b/tf6muxserver/schema_equality.go index f88f568..dc0a4db 100644 --- a/tf6muxserver/schema_equality.go +++ b/tf6muxserver/schema_equality.go @@ -15,6 +15,7 @@ var schemaCmpOptions = []cmp.Option{ cmpopts.SortSlices(func(i, j *tfprotov6.SchemaNestedBlock) bool { return i.TypeName < j.TypeName }), + cmpopts.IgnoreFields(tfprotov6.SchemaNestedBlock{}, "MinItems", "MaxItems"), } // schemaDiff outputs the difference between schemas while accounting for From 6f60293a4a5fb49181e313ef0bf111d3ca7c1c4e Mon Sep 17 00:00:00 2001 From: k-yomo Date: Tue, 20 Dec 2022 16:57:51 +0900 Subject: [PATCH 3/4] Update docr --- .../docs/plugin/mux/combining-protocol-version-5-providers.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/plugin/mux/combining-protocol-version-5-providers.mdx b/website/docs/plugin/mux/combining-protocol-version-5-providers.mdx index 7e5373f..fa9aa97 100644 --- a/website/docs/plugin/mux/combining-protocol-version-5-providers.mdx +++ b/website/docs/plugin/mux/combining-protocol-version-5-providers.mdx @@ -27,7 +27,7 @@ The following provider server implementations are supported: To be combined, provider servers must meet the following requirements: -* All provider schemas must match. +* All provider schemas (except block `MinItems`/`MaxItems`) must match. * All provider meta schemas must match. * Only one provider may implement each resource and data source. From 3069768d3e7cb77d212e2542625cb33f1858fab7 Mon Sep 17 00:00:00 2001 From: k-yomo Date: Tue, 20 Dec 2022 16:58:06 +0900 Subject: [PATCH 4/4] Add changelog --- .changelog/118.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/118.txt diff --git a/.changelog/118.txt b/.changelog/118.txt new file mode 100644 index 0000000..a4e9f4d --- /dev/null +++ b/.changelog/118.txt @@ -0,0 +1,3 @@ +```release-note:bug +tf5muxserver+tf6muxserver: Allow differing provider schema block `MinItems` and `MaxItems` as terraform-plugin-framework does not use those fields for configuration validation +```