@@ -11,6 +11,7 @@ import (
1111 "github.com/hashicorp/terraform/internal/configs/configschema"
1212 "github.com/hashicorp/terraform/internal/providers"
1313 proto "github.com/hashicorp/terraform/internal/tfplugin5"
14+ "github.com/zclconf/go-cty/cty"
1415)
1516
1617// ConfigSchemaToProto takes a *configschema.Block and converts it to a
@@ -111,6 +112,39 @@ func ProtoToActionSchema(s *proto.ActionSchema) providers.ActionSchema {
111112 }
112113}
113114
115+ func ProtoToListSchema (s * proto.Schema ) providers.Schema {
116+ listSchema := ProtoToProviderSchema (s , nil )
117+ itemCount := 0
118+ // check if the provider has set some attributes as required.
119+ // When yes, then we set minItem = 1, which
120+ // validates that the configuration contains a "config" block.
121+ for _ , attrS := range listSchema .Body .Attributes {
122+ if attrS .Required {
123+ itemCount = 1
124+ break
125+ }
126+ }
127+ return providers.Schema {
128+ Version : listSchema .Version ,
129+ Body : & configschema.Block {
130+ Attributes : map [string ]* configschema.Attribute {
131+ "data" : {
132+ Type : cty .DynamicPseudoType ,
133+ Computed : true ,
134+ },
135+ },
136+ BlockTypes : map [string ]* configschema.NestedBlock {
137+ "config" : {
138+ Block : * listSchema .Body ,
139+ Nesting : configschema .NestingSingle ,
140+ MinItems : itemCount ,
141+ MaxItems : itemCount ,
142+ },
143+ },
144+ },
145+ }
146+ }
147+
114148// ProtoToConfigSchema takes the GetSchcema_Block from a grpc response and converts it
115149// to a terraform *configschema.Block.
116150func ProtoToConfigSchema (b * proto.Schema_Block ) * configschema.Block {
0 commit comments