terraform-linters / tflint

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

tflint --recursive --call-module-type=all cannot find nested local modules #2081

Closed mdowling17 closed 4 months ago

mdowling17 commented 4 months ago

Summary

When running tflint --recursive --call-module-type=all with a file directory that contains nested local modules (that is local modules that call other remote/local modules), tflint says Error: "module1" module is not found. Did you run "terraform init"? It seems to expect that I go into each of my local modules and run terraform init. That seems totally unnecessary since it should be able to figure things out by looking at my root .terraform/modules folder created by running terraform init in the root.

Command

tflint --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 Configuration

plugin "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 Version

0.51.2

Terraform Version

1.5.7

Operating System