Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform {*} panics when on Terraform Plan files #5250

Open
scottford-io opened this issue Feb 20, 2025 · 0 comments
Open

terraform {*} panics when on Terraform Plan files #5250

scottford-io opened this issue Feb 20, 2025 · 0 comments

Comments

@scottford-io
Copy link
Contributor

Describe the bug
Running the query terraform {*} when connected to a Terraform Plan resource triggers a panic in cnquery/cnspec:

cnspec run terraform plan tfplan.json -c "terraform {*}"
→ user requested to ignore .terraform
→ loaded configuration from policy-development.yaml using source $MONDOO_CONFIG_PATH
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10584bd00]

goroutine 25 [running]:
github.com/hashicorp/hcl/v2/hclparse.(*Parser).Files(0x14000551518?)
	/home/runner/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.23.0/hclparse/parser.go:137
go.mondoo.com/cnquery/v11/providers/terraform/resources.(*mqlTerraform).files(0x1400069c000)
	/home/runner/_work/cnquery/cnquery/providers/terraform/resources/hcl.go:39 +0x48
go.mondoo.com/cnquery/v11/providers/terraform/resources.(*mqlTerraform).GetFiles.func1()
	/home/runner/_work/cnquery/cnquery/providers/terraform/resources/terraform.lr.go:892 +0x9c
go.mondoo.com/cnquery/v11/providers-sdk/v1/plugin.GetOrCompute[...](0x1400069c048?, 0x14000551618)
	/home/runner/_work/cnquery/cnquery/providers-sdk/v1/plugin/runtime.go:269 +0x38
go.mondoo.com/cnquery/v11/providers/terraform/resources.(*mqlTerraform).GetFiles(0x8?)
	/home/runner/_work/cnquery/cnquery/providers/terraform/resources/terraform.lr.go:881 +0x40
go.mondoo.com/cnquery/v11/providers/terraform/resources.init.func1({0x1060efd40?, 0x1400069c000?})
	/home/runner/_work/cnquery/cnquery/providers/terraform/resources/terraform.lr.go:149 +0x38
go.mondoo.com/cnquery/v11/providers/terraform/resources.GetData({0x1060efd40, 0x1400069c000}, {0x1400019839a, 0x5}, 0x140002b0230?)
	/home/runner/_work/cnquery/cnquery/providers/terraform/resources/terraform.lr.go:408 +0x130
go.mondoo.com/cnquery/v11/providers-sdk/v1/plugin.(*Service).GetData(0x1400010e6c0?, 0x140002b0230)
	/home/runner/_work/cnquery/cnquery/providers-sdk/v1/plugin/service.go:195 +0x288
go.mondoo.com/cnquery/v11/providers-sdk/v1/plugin.(*GRPCServer).GetData(0x10708e8d0?, {0x105fa03c0?, 0x140005488b8?}, 0x104ec7eb0?)
	/home/runner/_work/cnquery/cnquery/providers-sdk/v1/plugin/grpc.go:129 +0x2c
go.mondoo.com/cnquery/v11/providers-sdk/v1/plugin._ProviderPlugin_GetData_Handler({0x105fa03c0, 0x14000359780}, {0x1060fba00, 0x14000792210}, 0x140003f4280, 0x0)
	/home/runner/_work/cnquery/cnquery/providers-sdk/v1/plugin/plugin_grpc.pb.go:318 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x140001f5000, {0x1060fba00, 0x14000792180}, 0x14000114840, 0x140000b9500, 0x1070d0a10, 0x0)
	/home/runner/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1400 +0xc9c
google.golang.org/grpc.(*Server).handleStream(0x140001f5000, {0x1060fc2b0, 0x1400030c340}, 0x14000114840)
	/home/runner/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1810 +0x900
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	/home/runner/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1030 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 51
	/home/runner/go/pkg/mod/google.golang.org/grpc@v1.70.0/server.go:1041 +0x138
x plugin process exited error="exit status 2" id=56580 plugin=/Users/scottford/.config/mondoo/providers/terraform/terraform
2 errors occurred:
	* the 'terraform' provider crashed: rpc error: code = Unavailable desc = error reading from server: EOF
	* the 'terraform' provider crashed: rpc error: code = Unavailable desc = connection error: desc = "transport: error while dialing: dial unix /var/folders/st/1k_rcn4d2s14jkq2rtd7hgl40000gn/T/plugin1656233428: connect: connection refused"
terraform: {
  tfvars: the 'terraform' provider crashed: rpc error: code = Unavailable desc = connection error: desc = "transport: error while dialing: dial unix /var/folders/st/1k_rcn4d2s14jkq2rtd7hgl40000gn/T/plugin1656233428: connect: connection refused"
  outputs: []
  variables: []
  files: the 'terraform' provider crashed: rpc error: code = Unavailable desc = error reading from server: EOF
  modules: []
  datasources: the 'terraform' provider crashed: rpc error: code = Unavailable desc = connection error: desc = "transport: error while dialing: dial unix /var/folders/st/1k_rcn4d2s14jkq2rtd7hgl40000gn/T/plugin1656233428: connect: connection refused"
  blocks: the 'terraform' provider crashed: rpc error: code = Unavailable desc = connection error: desc = "transport: error while dialing: dial unix /var/folders/st/1k_rcn4d2s14jkq2rtd7hgl40000gn/T/plugin1656233428: connect: connection refused"
  resources: []
  providers: []
}
x failed to disconnect from provider terraform error="rpc error: code = Unavailable desc = connection error: desc = \"transport: error while dialing: dial unix /var/folders/st/1k_rcn4d2s14jkq2rtd7hgl40000gn/T/plugin1656233428: connect: connection refused\""
! removing closed provider provider=terraform

To Reproduce
Steps to reproduce the behavior:

  1. Create tfplan.json file (terraform plan -out tfplan.out && terraform show -json tfplan.out > tfplan.json)
  2. Run command cnspec run terraform plan tfplan.json -c "terraform {*}"

Expected behavior
This should return the data from the query.

Screenshots or CLI Output
If applicable, add screenshots or the CLI output to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. macOS]
  • OS Version: [e.g. 13.0]
  • Browser if applicable: [e.g. Chrome, Firefox]
  • Browser Version: [e.g. 106]

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant