-
IntroductionIntroductionI have a module that needs to call some other modules to run. I have looked at the DEBUG and it is looking for the wrong key as I will show in the evidencies below First an example of what I am doing with Terraform: File: terraform/do_something.tf module "do_something" {
source = "./modules/module1"
name = "some_name"
location = "eastus"
} File: terraform/modules/module1/main.tf module "this_should_be_run_by_another_module" {
source = "../module2"
name = var.name
location = var.location
} File: terraform/modules/module2/main.tf resource "azurerm_resource_group" "default" {
name =var.name
location = var.location
} File: .tflint.hcl config {
module = true
force = false
disabled_by_default = false
}
plugin "azurerm" {
enabled = true
version = "0.15.0"
source = "github.com/terraform-linters/tflint-ruleset-azurerm"
}
rule "terraform_comment_syntax" {
enabled = true
}
rule "terraform_deprecated_index" {
enabled = true
}
rule "terraform_naming_convention" {
enabled = true
}
rule "terraform_typed_variables" {
enabled = true
}
rule "terraform_unused_declarations" {
enabled = true
}
rule "terraform_unused_required_providers" {
enabled = true
}
rule "terraform_typed_variables" {
enabled = true
} --> Expected BehaviorI would expect that running the tflint it would not fail by module not found, terraform plan and apply runs normally Actual behaviorIt fails because it did not found the module. Error: `this_should_be_run_by_another_module` module is not found. Did you run `terraform init`?
on modules/module1/main.tf line 1, in module "this_should_be_run_by_another_module":
1: module "this_should_be_run_by_another_module" { Running the tflint in DEBUG mode, I got this: 23:13:37 loader.go:291: [DEBUG] Parsing the module manifest file: {"Modules":[{"Key":"helm_external_dns","Source":"./modules/helm","Dir":"modules/helm"},
...
{"Key":"do_something.this_should_be_run_by_another_module","Source":"../module2","Dir":"modules/module2"},
{"Key":"do_something","Source":"./modules/module1","Dir":"modules/module1"},
...
{"Key":"","Source":"","Dir":"."}]}
23:13:37 loader.go:82: [INFO] Load configurations under modules/module1/
23:13:37 loader.go:97: [INFO] Module inspection is enabled. Building a root module with children...
23:13:37 loader.go:263: [DEBUG] Failed to search by `module.this_should_be_run_by_another_module` key. Additional ContextSo what I found is that tflint is searching for the wrong Key. Terraform creates the key as do_something.<name_module> but tflint looks it as module.<name_module>. When it is a submodule it is not using the parent module name, but a standard "module" Example: $ tflint -v
TFLint version 0.38.1
+ ruleset.azurerm (0.15.0)
$ terraform --version
Terraform v1.0.11
on linux_amd64 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I checked for the same configuration, but couldn't reproduce it.
|
Beta Was this translation helpful? Give feedback.
-
The exact way to replicate this was missed from the original issue, this is reproducible.
|
Beta Was this translation helpful? Give feedback.
-
Thank you for your report. This seems to be a bug that occurs when module inspection is performed from outside of the module's directory. Opened #1508. |
Beta Was this translation helpful? Give feedback.
Thank you for your report. This seems to be a bug that occurs when module inspection is performed from outside of the module's directory. Opened #1508.