terraform-linters / tflint

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

Enable per-runner parallelism #1944

Closed wata727 closed 11 months ago

wata727 commented 11 months ago

See https://github.com/terraform-linters/tflint/issues/1943

As explained in https://github.com/terraform-linters/tflint/issues/1943, inspections on module calls are performed sequentially, which can be slow if there are many calls. This PR improves speed by processing in parallel with goroutines.

This can be expected to speed up when you have many module calls. For example, with 50 module calls, we observed the following improvements:

plugin "terraform" {
    enabled = false
}
plugin "google" {
    enabled = true
    version = "0.26.0"
    source  = "github.com/terraform-linters/tflint-ruleset-google"
}
module "module" {
  source = "./module"
  count  = 50
}
$ time tflint
real    0m0.774s
user    0m0.897s
sys     0m0.319s

$ time tflint --no-parallel-runners
real    0m1.591s
user    0m1.747s
sys     0m1.815s

Although the above improvement is small, it can be effective when inspecting many modules with recursive inspections.

Note that the inspection against the root module is not parallelized for goroutine-safety. The root module runner may be referenced from module calls, so it is not safe to share it between multiple goroutines, assuming autofix-like side effects. I believe there are no other unsafe operations like this, but just in case I'm adding the --no-parallel-runners flag for debugging.