Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions providers/terraform/resources/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ func (t *mqlTerraformBlock) id() (string, error) {
// NOTE: a hcl block is identified by its filename and position
fp := t.Start

if fp.State != plugin.StateIsSet || fp.Data == nil {
return "", errors.New("terraform block has invalid position data")
}

file := fp.Data.Path.Data
line := fp.Data.Line.Data
column := fp.Data.Column.Data
Expand Down Expand Up @@ -780,3 +784,11 @@ func getBlockByName(hb *hcl.Block, name string) *hcl.Block {
}
return nil
}

// initTerraformBlock provides initialization for terraform.block resource
// to safely handle direct queries without crashing when a block is queried
// without required parameters.
func initTerraformBlock(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) {
// Return a direct error instead of a resource with an error
return args, nil, errors.New("terraform.block cannot be queried directly. Use terraform.blocks(), terraform.resources(), terraform.file(path).blocks(), or other collection methods instead.")
}
2 changes: 1 addition & 1 deletion providers/terraform/resources/terraform.lr
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ terraform.fileposition {
}

// Terraform resource block
terraform.block @defaults("type labels") {
private terraform.block @defaults("type labels") {
// Block type
type string
// Block Labels
Expand Down
2 changes: 1 addition & 1 deletion providers/terraform/resources/terraform.lr.go

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

1 change: 1 addition & 0 deletions providers/terraform/resources/terraform.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ resources:
snippet: {}
start: {}
type: {}
is_private: true
maturity: experimental
min_mondoo_version: 5.15.0
platform:
Expand Down
Loading