@@ -11,6 +11,7 @@ import (
11
11
"github.com/hashicorp/terraform/internal/configs/configschema"
12
12
"github.com/hashicorp/terraform/internal/providers"
13
13
proto "github.com/hashicorp/terraform/internal/tfplugin5"
14
+ "github.com/zclconf/go-cty/cty"
14
15
)
15
16
16
17
// ConfigSchemaToProto takes a *configschema.Block and converts it to a
@@ -111,6 +112,39 @@ func ProtoToActionSchema(s *proto.ActionSchema) providers.ActionSchema {
111
112
}
112
113
}
113
114
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
+
114
148
// ProtoToConfigSchema takes the GetSchcema_Block from a grpc response and converts it
115
149
// to a terraform *configschema.Block.
116
150
func ProtoToConfigSchema (b * proto.Schema_Block ) * configschema.Block {
0 commit comments