tflint --recursive --call-module-type=all cannot find nested local modules #2082
-
SummaryWhen running Commandtflint --recursive --call-module-type=all Terraform Configuration$ tree
.
├── README.md
├── backend.tf
├── locals.tf
├── main.tf
├── modules
│ ├── module1
│ │ ├── main.tf
│ │ └── outputs.tf
│ ├── module2
│ │ ├── main.tf
│ │ └── variables.tf
│ ├── module3
│ │ ├── backend.tf
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── module4
│ │ ├── main.tf
│ │ └── variables.tf
│ ├── module5
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── module6
│ │ ├── main.tf
│ │ └── outputs.tf
│ └── module7
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
├── moved.tf
└── variables.tf TFLint Configurationplugin "terraform" {
enabled = true
preset = "recommended"
}
config {
call_module_type = "all"
}
rule "terraform_required_version" {
enabled = false
}
rule "terraform_required_providers" {
enabled = false
} Output│ Failed to run in modules/module7; exit status 1
Failed to load configurations; modules/module7/main.tf:23,1-33: "module8" module is not found. Did you run "terraform init"?; :
Error: "module8" module is not found. Did you run "terraform init"?
on modules/module7/main.tf line 23, in module "module8":
23: module "module8" {
│ Failed to run in modules/module3; exit status 1
Failed to load configurations; modules/module3/main.tf:14,1-16: "module9" module is not found. Did you run "terraform init"?; , and 1 other diagnostic(s):
Error: "module9" module is not found. Did you run "terraform init"?
on modules/module3/main.tf line 14, in module "module9":
14: module "module9" {
Error: "module10" module is not found. Did you run "terraform init"?
on modules/module3/main.tf line 20, in module "module10":
20: module "module10" { TFLint Version0.51.2 Terraform Version1.5.7 Operating System
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
If you recurse, those modules that you recurse into need to be properly initialized. Recursing and child module calls are entirely different things. Child modules have a formal tree relationship. Recursion assumes a tree structure of directories, but makes no logical assumptions about the relationships of those directories. Every recursed directory is an independent entity. When you've recursed into your child directories, there is no relationship that TFLint sees between your repository root and the module directory at that point. |
Beta Was this translation helpful? Give feedback.
-
Hi @mdowling17 , did you end up finding how to fix this issue? |
Beta Was this translation helpful? Give feedback.
Yes, as I described above, if I set use
tflint --recursive --call-module-type=local
it works as expected. The limitation is that it doesn't lint remote modules, which I actually didn't need for my use-case. However, if you want to lint everything, you must go into each module directory and run terraform init and then you can runtflint --recursive --call-module-type=all
from the root.