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

Tool throws a panic error when there is a null type in the ternary operator #1627

Open
cybersa opened this issue Oct 16, 2023 · 0 comments
Open

Comments

@cybersa
Copy link

cybersa commented Oct 16, 2023

  • terrascan version: v1.18.3
  • Operating System: Linux

Description

terrascan fails with panic error when I run it against the following terraform script.

resource "null_resource" "cluster" {
  provisioner "local-exec" {
    command = "echo '${var.rds_create_db ? "DBNAME" : null}' >> dbs.txt"
  }
}

Tool fails because of null type in the ternary operator. If I replace that null value with literal string "null" or something else, it's works fine.

What I Did

terrascan scan -f test.tf
panic: value is null

goroutine 1 [running]:
github.com/zclconf/go-cty/cty.Value.AsString({{{0x37398a8?, 0xc00081c75d?}}, {0x0?, 0x0?}})
	/home/runner/go/pkg/mod/github.com/zclconf/[email protected]/cty/value_ops.go:1259 +0x125
github.com/tenable/terrascan/pkg/iac-providers/terraform/commons.(*converter).convertStringPart(0xc00099eca0, {0x373a760?, 0xc0006ec480?})
	/home/runner/work/terrascan/terrascan/pkg/iac-providers/terraform/commons/convert.go:226 +0x109
github.com/tenable/terrascan/pkg/iac-providers/terraform/commons.(*converter).convertTemplateConditional(0xc00099eca0, 0xc0004a7c70)
	/home/runner/work/terrascan/terrascan/pkg/iac-providers/terraform/commons/convert.go:262 +0x456
github.com/tenable/terrascan/pkg/iac-providers/terraform/commons.(*converter).convertStringPart(0xc00099eca0, {0x373a660?, 0xc0004a7c70?})
	/home/runner/work/terrascan/terrascan/pkg/iac-providers/terraform/commons/convert.go:232 +0x185
github.com/tenable/terrascan/pkg/iac-providers/terraform/commons.(*converter).convertTemplate(0x1?, 0x1?)
	/home/runner/work/terrascan/terrascan/pkg/iac-providers/terraform/commons/convert.go:210 +0x107
github.com/tenable/terrascan/pkg/iac-providers/terraform/commons.(*converter).convertExpression(0xc00099eca0, {0x373a920, 0xc0006ec7e0})
	/home/runner/work/terrascan/terrascan/pkg/iac-providers/terraform/commons/convert.go:166 +0x272
github.com/tenable/terrascan/pkg/iac-providers/terraform/commons.(*converter).convertBody(0x203000?, 0xc000654bb0)
	/home/runner/work/terrascan/terrascan/pkg/iac-providers/terraform/commons/convert.go:56 +0xe7
github.com/tenable/terrascan/pkg/iac-providers/terraform/commons.(*converter).convertBlock(0x8?, 0xc0004385a0, 0xc00099e8e8, 0xc00099e8b8)
	/home/runner/work/terrascan/terrascan/pkg/iac-providers/terraform/commons/convert.go:97 +0x65
github.com/tenable/terrascan/pkg/iac-providers/terraform/commons.(*converter).convertBody(0xc00044cc90?, 0xc000654fd0)
	/home/runner/work/terrascan/terrascan/pkg/iac-providers/terraform/commons/convert.go:70 +0x314
github.com/tenable/terrascan/pkg/iac-providers/terraform/commons.CreateResourceConfig(_)
	/home/runner/work/terrascan/terrascan/pkg/iac-providers/terraform/commons/resource.go:48 +0x125
github.com/tenable/terrascan/pkg/iac-providers/terraform/commons.LoadIacFile({0xc00044cc90, 0x22}, {0x305c94c, 0x6})
	/home/runner/work/terrascan/terrascan/pkg/iac-providers/terraform/commons/load-file.go:58 +0x499
github.com/tenable/terrascan/pkg/iac-providers/terraform/v15.(*TfV15).LoadIacFile(0x29da420, {0xc00044cc90?, 0x3068455?}, 0xb?)
	/home/runner/work/terrascan/terrascan/pkg/iac-providers/terraform/v15/load-file.go:26 +0x30
github.com/tenable/terrascan/pkg/runtime.(*Executor).Execute(0xc000928a80, 0x0, 0x0)
	/home/runner/work/terrascan/terrascan/pkg/runtime/executor.go:226 +0x1d9
github.com/tenable/terrascan/pkg/cli.(*ScanOptions).Run(0xc000581520)
	/home/runner/work/terrascan/terrascan/pkg/cli/run.go:218 +0x44a
github.com/tenable/terrascan/pkg/cli.(*ScanOptions).Scan(0x0?)
	/home/runner/work/terrascan/terrascan/pkg/cli/run.go:140 +0x1b7
github.com/tenable/terrascan/pkg/cli.scan(0x4ea5300?, {0xc0003fa540?, 0x2?, 0x2?})
	/home/runner/work/terrascan/terrascan/pkg/cli/scan.go:55 +0x11f
github.com/spf13/cobra.(*Command).execute(0x4ea5300, {0xc0003fa520, 0x2, 0x2})
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:916 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0x4ea5020)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1044 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:968
github.com/tenable/terrascan/pkg/cli.Execute()
	/home/runner/work/terrascan/terrascan/pkg/cli/register.go:98 +0x435
main.main()
	/home/runner/work/terrascan/terrascan/cmd/terrascan/main.go:22 +0x17
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