@@ -18,6 +18,8 @@ import (
18
18
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
19
19
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
20
20
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testprovider"
21
+ "github.com/hashicorp/terraform-plugin-framework/list"
22
+ listschema "github.com/hashicorp/terraform-plugin-framework/list/schema"
21
23
"github.com/hashicorp/terraform-plugin-framework/provider"
22
24
"github.com/hashicorp/terraform-plugin-framework/provider/metaschema"
23
25
providerschema "github.com/hashicorp/terraform-plugin-framework/provider/schema"
@@ -41,6 +43,7 @@ func TestServerGetProviderSchema(t *testing.T) {
41
43
DataSourceSchemas : map [string ]fwschema.Schema {},
42
44
EphemeralResourceSchemas : map [string ]fwschema.Schema {},
43
45
FunctionDefinitions : map [string ]function.Definition {},
46
+ ListResourceSchemas : map [string ]fwschema.Schema {},
44
47
Provider : providerschema.Schema {},
45
48
ResourceSchemas : map [string ]fwschema.Schema {},
46
49
ServerCapabilities : & fwserver.ServerCapabilities {
@@ -111,6 +114,7 @@ func TestServerGetProviderSchema(t *testing.T) {
111
114
},
112
115
EphemeralResourceSchemas : map [string ]fwschema.Schema {},
113
116
FunctionDefinitions : map [string ]function.Definition {},
117
+ ListResourceSchemas : map [string ]fwschema.Schema {},
114
118
Provider : providerschema.Schema {},
115
119
ResourceSchemas : map [string ]fwschema.Schema {},
116
120
ServerCapabilities : & fwserver.ServerCapabilities {
@@ -318,6 +322,7 @@ func TestServerGetProviderSchema(t *testing.T) {
318
322
},
319
323
EphemeralResourceSchemas : map [string ]fwschema.Schema {},
320
324
FunctionDefinitions : map [string ]function.Definition {},
325
+ ListResourceSchemas : map [string ]fwschema.Schema {},
321
326
Provider : providerschema.Schema {},
322
327
ResourceSchemas : map [string ]fwschema.Schema {},
323
328
ServerCapabilities : & fwserver.ServerCapabilities {
@@ -388,6 +393,7 @@ func TestServerGetProviderSchema(t *testing.T) {
388
393
},
389
394
},
390
395
FunctionDefinitions : map [string ]function.Definition {},
396
+ ListResourceSchemas : map [string ]fwschema.Schema {},
391
397
Provider : providerschema.Schema {},
392
398
ResourceSchemas : map [string ]fwschema.Schema {},
393
399
ServerCapabilities : & fwserver.ServerCapabilities {
@@ -601,6 +607,7 @@ func TestServerGetProviderSchema(t *testing.T) {
601
607
},
602
608
},
603
609
FunctionDefinitions : map [string ]function.Definition {},
610
+ ListResourceSchemas : map [string ]fwschema.Schema {},
604
611
Provider : providerschema.Schema {},
605
612
ResourceSchemas : map [string ]fwschema.Schema {},
606
613
ServerCapabilities : & fwserver.ServerCapabilities {
@@ -655,8 +662,9 @@ func TestServerGetProviderSchema(t *testing.T) {
655
662
Return : function.StringReturn {},
656
663
},
657
664
},
658
- Provider : providerschema.Schema {},
659
- ResourceSchemas : map [string ]fwschema.Schema {},
665
+ ListResourceSchemas : map [string ]fwschema.Schema {},
666
+ Provider : providerschema.Schema {},
667
+ ResourceSchemas : map [string ]fwschema.Schema {},
660
668
ServerCapabilities : & fwserver.ServerCapabilities {
661
669
GetProviderSchemaOptional : true ,
662
670
MoveResourceState : true ,
@@ -808,6 +816,158 @@ func TestServerGetProviderSchema(t *testing.T) {
808
816
},
809
817
},
810
818
},
819
+ "listresource-schemas" : {
820
+ server : & fwserver.Server {
821
+ Provider : & testprovider.Provider {
822
+ ListResourcesMethod : func (_ context.Context ) []func () list.ListResource {
823
+ return []func () list.ListResource {
824
+ func () list.ListResource {
825
+ return & testprovider.ListResource {
826
+ ListResourceConfigSchemaMethod : func (_ context.Context , _ list.ListResourceSchemaRequest , resp * list.ListResourceSchemaResponse ) {
827
+ resp .Schema = listschema.Schema {
828
+ Attributes : map [string ]listschema.Attribute {
829
+ "test1" : listschema.StringAttribute {
830
+ Required : true ,
831
+ },
832
+ },
833
+ }
834
+ },
835
+ MetadataMethod : func (_ context.Context , _ resource.MetadataRequest , resp * resource.MetadataResponse ) {
836
+ resp .TypeName = "test_resource"
837
+ },
838
+ }
839
+ },
840
+ }
841
+ },
842
+ ResourcesMethod : func (_ context.Context ) []func () resource.Resource {
843
+ return []func () resource.Resource {
844
+ func () resource.Resource {
845
+ return & testprovider.Resource {
846
+ SchemaMethod : func (_ context.Context , _ resource.SchemaRequest , resp * resource.SchemaResponse ) {
847
+ resp .Schema = resourceschema.Schema {
848
+ Attributes : map [string ]resourceschema.Attribute {
849
+ "test1" : resourceschema.StringAttribute {
850
+ Required : true ,
851
+ },
852
+ },
853
+ }
854
+ },
855
+ MetadataMethod : func (_ context.Context , _ resource.MetadataRequest , resp * resource.MetadataResponse ) {
856
+ resp .TypeName = "test_resource"
857
+ },
858
+ }
859
+ },
860
+ }
861
+ },
862
+ },
863
+ },
864
+ request : & fwserver.GetProviderSchemaRequest {},
865
+ expectedResponse : & fwserver.GetProviderSchemaResponse {
866
+ DataSourceSchemas : map [string ]fwschema.Schema {},
867
+ EphemeralResourceSchemas : map [string ]fwschema.Schema {},
868
+ FunctionDefinitions : map [string ]function.Definition {},
869
+ ListResourceSchemas : map [string ]fwschema.Schema {
870
+ "test_resource" : listschema.Schema {
871
+ Attributes : map [string ]listschema.Attribute {
872
+ "test1" : listschema.StringAttribute {
873
+ Required : true ,
874
+ },
875
+ },
876
+ },
877
+ },
878
+ Provider : providerschema.Schema {},
879
+ ResourceSchemas : map [string ]fwschema.Schema {
880
+ "test_resource" : resourceschema.Schema {
881
+ Attributes : map [string ]resourceschema.Attribute {
882
+ "test1" : resourceschema.StringAttribute {
883
+ Required : true ,
884
+ },
885
+ },
886
+ },
887
+ },
888
+ ServerCapabilities : & fwserver.ServerCapabilities {
889
+ GetProviderSchemaOptional : true ,
890
+ MoveResourceState : true ,
891
+ PlanDestroy : true ,
892
+ },
893
+ },
894
+ },
895
+ "listresource-schemas-invalid-attribute-name" : {
896
+ server : & fwserver.Server {
897
+ Provider : & testprovider.Provider {
898
+ ListResourcesMethod : func (_ context.Context ) []func () list.ListResource {
899
+ return []func () list.ListResource {
900
+ func () list.ListResource {
901
+ return & testprovider.ListResource {
902
+ ListResourceConfigSchemaMethod : func (_ context.Context , _ list.ListResourceSchemaRequest , resp * list.ListResourceSchemaResponse ) {
903
+ resp .Schema = listschema.Schema {
904
+ Attributes : map [string ]listschema.Attribute {
905
+ "$filter" : listschema.StringAttribute {
906
+ Required : true ,
907
+ },
908
+ },
909
+ }
910
+ },
911
+ MetadataMethod : func (_ context.Context , _ resource.MetadataRequest , resp * resource.MetadataResponse ) {
912
+ resp .TypeName = "test_resource"
913
+ },
914
+ }
915
+ },
916
+ }
917
+ },
918
+ ResourcesMethod : func (_ context.Context ) []func () resource.Resource {
919
+ return []func () resource.Resource {
920
+ func () resource.Resource {
921
+ return & testprovider.Resource {
922
+ SchemaMethod : func (_ context.Context , _ resource.SchemaRequest , resp * resource.SchemaResponse ) {
923
+ resp .Schema = resourceschema.Schema {
924
+ Attributes : map [string ]resourceschema.Attribute {
925
+ "name" : resourceschema.StringAttribute {
926
+ Required : true ,
927
+ },
928
+ },
929
+ }
930
+ },
931
+ MetadataMethod : func (_ context.Context , _ resource.MetadataRequest , resp * resource.MetadataResponse ) {
932
+ resp .TypeName = "test_resource"
933
+ },
934
+ }
935
+ },
936
+ }
937
+ },
938
+ },
939
+ },
940
+ request : & fwserver.GetProviderSchemaRequest {},
941
+ expectedResponse : & fwserver.GetProviderSchemaResponse {
942
+ Provider : providerschema.Schema {},
943
+ DataSourceSchemas : map [string ]fwschema.Schema {},
944
+ EphemeralResourceSchemas : map [string ]fwschema.Schema {},
945
+ FunctionDefinitions : map [string ]function.Definition {},
946
+ ResourceSchemas : map [string ]fwschema.Schema {
947
+ "test_resource" : resourceschema.Schema {
948
+ Attributes : map [string ]resourceschema.Attribute {
949
+ "name" : resourceschema.StringAttribute {
950
+ Required : true ,
951
+ },
952
+ },
953
+ },
954
+ },
955
+ ServerCapabilities : & fwserver.ServerCapabilities {
956
+ GetProviderSchemaOptional : true ,
957
+ MoveResourceState : true ,
958
+ PlanDestroy : true ,
959
+ },
960
+ Diagnostics : diag.Diagnostics {
961
+ diag .NewErrorDiagnostic (
962
+ "Invalid Attribute/Block Name" ,
963
+ "When validating the schema, an implementation issue was found. " +
964
+ "This is always an issue with the provider and should be reported to the provider developers.\n \n " +
965
+ "\" $filter\" at schema path \" $filter\" is an invalid attribute/block name. " +
966
+ "Names must only contain lowercase alphanumeric characters (a-z, 0-9) and underscores (_)." ,
967
+ ),
968
+ },
969
+ },
970
+ },
811
971
"provider" : {
812
972
server : & fwserver.Server {
813
973
Provider : & testprovider.Provider {
@@ -827,6 +987,7 @@ func TestServerGetProviderSchema(t *testing.T) {
827
987
DataSourceSchemas : map [string ]fwschema.Schema {},
828
988
EphemeralResourceSchemas : map [string ]fwschema.Schema {},
829
989
FunctionDefinitions : map [string ]function.Definition {},
990
+ ListResourceSchemas : map [string ]fwschema.Schema {},
830
991
Provider : providerschema.Schema {
831
992
Attributes : map [string ]providerschema.Attribute {
832
993
"test" : providerschema.StringAttribute {
@@ -894,6 +1055,7 @@ func TestServerGetProviderSchema(t *testing.T) {
894
1055
DataSourceSchemas : map [string ]fwschema.Schema {},
895
1056
EphemeralResourceSchemas : map [string ]fwschema.Schema {},
896
1057
FunctionDefinitions : map [string ]function.Definition {},
1058
+ ListResourceSchemas : map [string ]fwschema.Schema {},
897
1059
Provider : providerschema.Schema {},
898
1060
ProviderMeta : metaschema.Schema {
899
1061
Attributes : map [string ]metaschema.Attribute {
@@ -990,6 +1152,7 @@ func TestServerGetProviderSchema(t *testing.T) {
990
1152
DataSourceSchemas : map [string ]fwschema.Schema {},
991
1153
EphemeralResourceSchemas : map [string ]fwschema.Schema {},
992
1154
FunctionDefinitions : map [string ]function.Definition {},
1155
+ ListResourceSchemas : map [string ]fwschema.Schema {},
993
1156
Provider : providerschema.Schema {},
994
1157
ResourceSchemas : map [string ]fwschema.Schema {
995
1158
"test_resource1" : resourceschema.Schema {
@@ -1203,6 +1366,7 @@ func TestServerGetProviderSchema(t *testing.T) {
1203
1366
DataSourceSchemas : map [string ]fwschema.Schema {},
1204
1367
EphemeralResourceSchemas : map [string ]fwschema.Schema {},
1205
1368
FunctionDefinitions : map [string ]function.Definition {},
1369
+ ListResourceSchemas : map [string ]fwschema.Schema {},
1206
1370
Provider : providerschema.Schema {},
1207
1371
ResourceSchemas : map [string ]fwschema.Schema {
1208
1372
"testprovidertype_resource" : resourceschema.Schema {
0 commit comments