@@ -146,6 +146,23 @@ func providerProtoSchema() *proto.GetProviderSchema_Response {
146146 Required : true ,
147147 },
148148 },
149+ BlockTypes : []* proto.Schema_NestedBlock {
150+ {
151+ TypeName : "nested_filter" ,
152+ Nesting : proto .Schema_NestedBlock_SINGLE ,
153+ Block : & proto.Schema_Block {
154+ Attributes : []* proto.Schema_Attribute {
155+ {
156+ Name : "nested_attr" ,
157+ Type : []byte (`"string"` ),
158+ Required : false ,
159+ },
160+ },
161+ },
162+ MinItems : 1 ,
163+ MaxItems : 1 ,
164+ },
165+ },
149166 },
150167 },
151168 },
@@ -466,7 +483,7 @@ func TestGRPCProvider_ValidateListResourceConfig(t *testing.T) {
466483 gomock .Any (),
467484 ).Return (& proto.ValidateListResourceConfig_Response {}, nil )
468485
469- cfg := hcl2shim .HCL2ValueFromConfigValue (map [string ]interface {}{"config" : map [string ]interface {}{"filter_attr" : "value" }})
486+ cfg := hcl2shim .HCL2ValueFromConfigValue (map [string ]interface {}{"config" : map [string ]interface {}{"filter_attr" : "value" , "nested_filter" : map [ string ] interface {}{ "nested_attr" : "value" } }})
470487 resp := p .ValidateListResourceConfig (providers.ValidateListResourceConfigRequest {
471488 TypeName : "list" ,
472489 Config : cfg ,
@@ -478,8 +495,18 @@ func TestGRPCProvider_ValidateListResourceConfig_OptionalCfg(t *testing.T) {
478495 ctrl := gomock .NewController (t )
479496 client := mockproto .NewMockProviderClient (ctrl )
480497 sch := providerProtoSchema ()
481- sch .ListResourceSchemas ["list" ].Block .Attributes [0 ].Optional = true
482- sch .ListResourceSchemas ["list" ].Block .Attributes [0 ].Required = false
498+
499+ // mock the schema in a way that makes the config attributes optional
500+ listSchema := sch .ListResourceSchemas ["list" ].Block
501+ // filter_attr is optional
502+ listSchema .Attributes [0 ].Optional = true
503+ listSchema .Attributes [0 ].Required = false
504+
505+ // nested_filter is optional
506+ listSchema .BlockTypes [0 ].MinItems = 0
507+ listSchema .BlockTypes [0 ].MaxItems = 0
508+
509+ sch .ListResourceSchemas ["list" ].Block = listSchema
483510 // we always need a GetSchema method
484511 client .EXPECT ().GetSchema (
485512 gomock .Any (),
@@ -502,10 +529,15 @@ func TestGRPCProvider_ValidateListResourceConfig_OptionalCfg(t *testing.T) {
502529 gomock .Any (),
503530 ).Return (& proto.ValidateListResourceConfig_Response {}, nil )
504531
505- cfg := hcl2shim .HCL2ValueFromConfigValue (map [string ]interface {}{})
532+ converted := convert .ProtoToListSchema (sch .ListResourceSchemas ["list" ])
533+ cfg := hcl2shim .HCL2ValueFromConfigValue (map [string ]any {})
534+ coercedCfg , err := converted .Body .CoerceValue (cfg )
535+ if err != nil {
536+ t .Fatalf ("failed to coerce config: %v" , err )
537+ }
506538 resp := p .ValidateListResourceConfig (providers.ValidateListResourceConfigRequest {
507539 TypeName : "list" ,
508- Config : cfg ,
540+ Config : coercedCfg ,
509541 })
510542 checkDiags (t , resp .Diagnostics )
511543}
@@ -1438,8 +1470,25 @@ func TestGRPCProvider_GetSchema_ListResourceTypes(t *testing.T) {
14381470 Required : true ,
14391471 },
14401472 },
1473+ BlockTypes : map [string ]* configschema.NestedBlock {
1474+ "nested_filter" : {
1475+ Block : configschema.Block {
1476+ Attributes : map [string ]* configschema.Attribute {
1477+ "nested_attr" : {
1478+ Type : cty .String ,
1479+ Required : false ,
1480+ },
1481+ },
1482+ },
1483+ Nesting : configschema .NestingSingle ,
1484+ MinItems : 1 ,
1485+ MaxItems : 1 ,
1486+ },
1487+ },
14411488 },
1442- Nesting : configschema .NestingSingle ,
1489+ Nesting : configschema .NestingSingle ,
1490+ MinItems : 1 ,
1491+ MaxItems : 1 ,
14431492 },
14441493 },
14451494 },
@@ -1485,6 +1534,9 @@ func TestGRPCProvider_Encode(t *testing.T) {
14851534 Before : cty .NullVal (cty .Object (map [string ]cty.Type {
14861535 "config" : cty .Object (map [string ]cty.Type {
14871536 "filter_attr" : cty .String ,
1537+ "nested_filter" : cty .Object (map [string ]cty.Type {
1538+ "nested_attr" : cty .String ,
1539+ }),
14881540 }),
14891541 "data" : cty .List (cty .Object (map [string ]cty.Type {
14901542 "state" : cty .Object (map [string ]cty.Type {
@@ -1498,6 +1550,9 @@ func TestGRPCProvider_Encode(t *testing.T) {
14981550 After : cty .ObjectVal (map [string ]cty.Value {
14991551 "config" : cty .ObjectVal (map [string ]cty.Value {
15001552 "filter_attr" : cty .StringVal ("value" ),
1553+ "nested_filter" : cty .ObjectVal (map [string ]cty.Value {
1554+ "nested_attr" : cty .StringVal ("value" ),
1555+ }),
15011556 }),
15021557 "data" : cty .ListVal ([]cty.Value {
15031558 cty .ObjectVal (map [string ]cty.Value {
@@ -1649,6 +1704,9 @@ func TestGRPCProvider_ListResource(t *testing.T) {
16491704 configVal := cty .ObjectVal (map [string ]cty.Value {
16501705 "config" : cty .ObjectVal (map [string ]cty.Value {
16511706 "filter_attr" : cty .StringVal ("filter-value" ),
1707+ "nested_filter" : cty .ObjectVal (map [string ]cty.Value {
1708+ "nested_attr" : cty .StringVal ("value" ),
1709+ }),
16521710 }),
16531711 })
16541712 request := providers.ListResourceRequest {
@@ -1731,6 +1789,9 @@ func TestGRPCProvider_ListResource_Error(t *testing.T) {
17311789 configVal := cty .ObjectVal (map [string ]cty.Value {
17321790 "config" : cty .ObjectVal (map [string ]cty.Value {
17331791 "filter_attr" : cty .StringVal ("filter-value" ),
1792+ "nested_filter" : cty .ObjectVal (map [string ]cty.Value {
1793+ "nested_attr" : cty .StringVal ("value" ),
1794+ }),
17341795 }),
17351796 })
17361797 request := providers.ListResourceRequest {
@@ -1746,6 +1807,9 @@ func TestGRPCProvider_ListResource_Diagnostics(t *testing.T) {
17461807 configVal := cty .ObjectVal (map [string ]cty.Value {
17471808 "config" : cty .ObjectVal (map [string ]cty.Value {
17481809 "filter_attr" : cty .StringVal ("filter-value" ),
1810+ "nested_filter" : cty .ObjectVal (map [string ]cty.Value {
1811+ "nested_attr" : cty .StringVal ("value" ),
1812+ }),
17491813 }),
17501814 })
17511815 request := providers.ListResourceRequest {
@@ -2009,6 +2073,9 @@ func TestGRPCProvider_ListResource_Limit(t *testing.T) {
20092073 configVal := cty .ObjectVal (map [string ]cty.Value {
20102074 "config" : cty .ObjectVal (map [string ]cty.Value {
20112075 "filter_attr" : cty .StringVal ("filter-value" ),
2076+ "nested_filter" : cty .ObjectVal (map [string ]cty.Value {
2077+ "nested_attr" : cty .StringVal ("value" ),
2078+ }),
20122079 }),
20132080 })
20142081 request := providers.ListResourceRequest {
0 commit comments