Skip to content

Commit

Permalink
🐛 fix terraform block filter to work with non-HCL
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus committed Sep 27, 2023
1 parent 3732f23 commit a417e1c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions providers/terraform/resources/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ func (t *mqlTerraform) blocks() ([]interface{}, error) {

func filterBlockByType(runtime *plugin.Runtime, filterType string) ([]interface{}, error) {
conn := runtime.Connection.(*connection.Connection)
files := conn.Parser().Files()
parsed := conn.Parser()
if parsed == nil {
// no results, because this is not a regular parsed HCL
return []interface{}{}, nil
}

files := parsed.Files()

var mqlHclBlocks []interface{}
for k := range files {
Expand Down Expand Up @@ -546,9 +552,11 @@ func initTerraformSettings(runtime *plugin.Runtime, args map[string]*llx.RawData

if len(blocks) != 1 {
// no terraform settings block found, this is ok for terraform and not an error
args["block"] = nil
args["requiredProviders"] = llx.DictData(map[string]interface{}{})
return args, nil, nil
// TODO: return modified arguments to load from recording
return nil, &mqlTerraformSettings{
Block: plugin.TValue[*mqlTerraformBlock]{State: plugin.StateIsSet | plugin.StateIsNull},
RequiredProviders: plugin.TValue[interface{}]{State: plugin.StateIsSet, Data: []interface{}{}},
}, nil
}

settingsBlock := blocks[0].(*mqlTerraformBlock)
Expand Down

0 comments on commit a417e1c

Please sign in to comment.