Skip to content

Commit

Permalink
🐛 migrate missing terraform.settings
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 ac8dfed commit 3732f23
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"type": "go",
"request": "launch",
"program": "${workspaceRoot}/apps/cnquery/cnquery.go",
"cwd": "${workspaceRoot}/",
"args": [
"run",
"local",
Expand Down
33 changes: 31 additions & 2 deletions providers/terraform/resources/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,37 @@ func (t *mqlTerraformModule) block() (*mqlTerraformBlock, error) {
return mqlHclBlock, nil
}

func (g *mqlTerraformSettings) id() (string, error) {
return "terraform.settings", nil
func initTerraformSettings(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) {
blocks, err := filterBlockByType(runtime, "terraform")
if err != nil {
return nil, nil, err
}

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
}

settingsBlock := blocks[0].(*mqlTerraformBlock)
args["block"] = llx.ResourceData(settingsBlock, "terraform.block")
args["requiredProviders"] = llx.DictData(map[string]interface{}{})

if settingsBlock.block.State == plugin.StateIsSet {
hb := settingsBlock.block.Data
requireProviderBlock := getBlockByName(hb, "required_providers")
if requireProviderBlock != nil {
attributes, _ := requireProviderBlock.Body.JustAttributes()
dict, err := hclResolvedAttributesToDict(attributes)
if err != nil {
return nil, nil, err
}
args["requiredProviders"] = llx.DictData(dict)
}
}

return args, nil, nil
}

func getBlockByName(hb *hcl.Block, name string) *hcl.Block {
Expand Down
9 changes: 2 additions & 7 deletions providers/terraform/resources/terraform.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3732f23

Please sign in to comment.