@@ -156,7 +156,80 @@ func dataSourcesFunc(runner tflint.Runner) *function3 {
156
156
},
157
157
},
158
158
Func : func (_ rego.BuiltinContext , dataType * ast.Term , schema * ast.Term , options * ast.Term ) (* ast.Term , error ) {
159
- return typedBlockFunc (dataType , schema , options , "data" , runner )
159
+ var typeName string
160
+ if err := ast .As (dataType .Value , & typeName ); err != nil {
161
+ return nil , err
162
+ }
163
+ var schemaJSON map [string ]any
164
+ if err := ast .As (schema .Value , & schemaJSON ); err != nil {
165
+ return nil , err
166
+ }
167
+ innerSchema , tyMap , err := jsonToSchema (schemaJSON , map [string ]cty.Type {}, "schema" )
168
+ if err != nil {
169
+ return nil , err
170
+ }
171
+ var optionJSON map [string ]string
172
+ if err := ast .As (options .Value , & optionJSON ); err != nil {
173
+ return nil , err
174
+ }
175
+ option , err := jsonToOption (optionJSON )
176
+ if err != nil {
177
+ return nil , err
178
+ }
179
+
180
+ content , err := runner .GetModuleContent (& hclext.BodySchema {
181
+ Blocks : []hclext.BlockSchema {
182
+ {
183
+ Type : "data" ,
184
+ LabelNames : []string {"type" , "name" },
185
+ Body : innerSchema ,
186
+ },
187
+ {
188
+ Type : "check" ,
189
+ LabelNames : []string {"name" },
190
+ Body : & hclext.BodySchema {
191
+ Blocks : []hclext.BlockSchema {
192
+ {
193
+ Type : "data" ,
194
+ LabelNames : []string {"type" , "name" },
195
+ Body : innerSchema ,
196
+ },
197
+ },
198
+ },
199
+ },
200
+ },
201
+ }, option .AsGetModuleContentOptions ())
202
+ if err != nil {
203
+ return nil , err
204
+ }
205
+
206
+ blocks := []* hclext.Block {}
207
+ for _ , block := range content .Blocks {
208
+ switch block .Type {
209
+ case "data" :
210
+ // "*" is a special character that returns all blocks
211
+ if typeName == block .Labels [0 ] || typeName == "*" {
212
+ blocks = append (blocks , block )
213
+ }
214
+ case "check" :
215
+ for _ , inner := range block .Body .Blocks {
216
+ if typeName == inner .Labels [0 ] || typeName == "*" {
217
+ blocks = append (blocks , inner )
218
+ }
219
+ }
220
+ }
221
+ }
222
+
223
+ out , err := typedBlocksToJSON (blocks , tyMap , "schema" , runner )
224
+ if err != nil {
225
+ return nil , err
226
+ }
227
+ v , err := ast .InterfaceToValue (out )
228
+ if err != nil {
229
+ return nil , err
230
+ }
231
+
232
+ return ast .NewTerm (v ), nil
160
233
},
161
234
}
162
235
}
0 commit comments