terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.98k stars 357 forks source link

Fix panic for module calls without source #1950

Closed wata727 closed 10 months ago

wata727 commented 11 months ago

See also https://github.com/terraform-linters/tflint-ruleset-opa/pull/80

TFLint v0.50 now automatically calls local modules, so calling a module without a source attribute now causes a panic:

$ cat main.tf
module "no_source" {}

$ tflint
Panic: unexpected module source type: <nil>
 -> 0: main.main.func1: /main.go(25)
 -> 1: runtime.gopanic: /panic.go(914)
 -> 2: github.com/terraform-linters/tflint/terraform.(*Loader).LoadConfig.(*Loader).moduleWalkerFunc.func4: /loader.go(143)
 -> 3: github.com/terraform-linters/tflint/terraform.ModuleWalkerFunc.LoadModule: /config.go(167)
 -> 4: github.com/terraform-linters/tflint/terraform.buildChildModules: /config.go(106)
 -> 5: github.com/terraform-linters/tflint/terraform.BuildConfig: /config.go(63)
 -> 6: github.com/terraform-linters/tflint/terraform.(*Loader).LoadConfig: /loader.go(89)
 -> 7: github.com/terraform-linters/tflint/cmd.(*CLI).setupRunners: /inspect.go(234)
 -> 8: github.com/terraform-linters/tflint/cmd.(*CLI).inspectModule: /inspect.go(131)
 -> 9: github.com/terraform-linters/tflint/cmd.(*CLI).inspect.func1: /inspect.go(54)
 -> 10: github.com/terraform-linters/tflint/cmd.(*CLI).withinChangedDir: /cli.go(187)
 -> 11: github.com/terraform-linters/tflint/cmd.(*CLI).inspect: /inspect.go(35)
 -> 12: github.com/terraform-linters/tflint/cmd.(*CLI).Run: /cli.go(106)
 -> 13: main.main: /main.go(38)
 -> 14: runtime.main: /proc.go(267)
 -> 15: runtime.goexit: /asm_amd64.s(1650)

TFLint crashed... :(
Please attach an output log, describe the situation and version that occurred and post an issue to https://github.com/terraform-linters/tflint/issues

Normally, calling a module without source is invalid, but it is undesirable to cause a panic. This PR changes the module walker to simply ignore such module calls, which prevents the panic.