VladRassokhin / intellij-hcl

HCL language support for IntelliJ platform based IDEs
Apache License 2.0
244 stars 47 forks source link

Module discovery only looks in parent directories so some modules are not located #317

Open mbrookson opened 3 years ago

mbrookson commented 3 years ago

Thank you for opening an issue. In this template paragraph text could be removed, however please retain headers.

Prerequisites

Installation details

Terraform Configuration Files

image image image

configuration/backend/main.tf

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"

  # ...other code not relevant
}

We have an environments/{env} directory which contains the entry point for our infrastructure per environment, therefore each directory has its own .terraform directory created. We then call into our core configuration like so

module "backend" {
    source = "../../configuration/backend"
}

Expected Behavior

When using external modules from a registry, modules in sibling directories outside of the parent/child hierarchy are still discovered by the IDE.

Actual Behavior

When using external modules from a registry, even after running terraform get it still cannot locate the external module. The terraform program itself seems to work fine and the module is installed in .terraform. I assume this is not working because the module code is stored in .terraform which is outside of the parent/child hierarchy.

Steps to Reproduce

See above example code

Perhaps this could be achieved by allowing module scopes/discovery paths to be a configurable setting for the plugin?

VladRassokhin commented 3 years ago

Unfortunately for now plugin doesn't have any features to support complex code structures, it just goes up in directories tree until .terraform found. It's a bit unclear for me how to properly support that, proper fix will require some configurations files or super-smart heuristics. As workaround I could suggest symlinking .terraform from environments/{env}/.terraform to your project root.

Is that correct that you invoke any terraform commands only in environments/{env} directories?

mbrookson commented 3 years ago

@VladRassokhin Thanks for the reply.

Yeah that's correct, all terraform is invoked via environments/{env}.

Was wondering whether it would be viable to add to the Terrform settings in the IDE? There is a similar feature for SQL Resolution Scopes where you can tell the IDE where to look. Pressing the + button in the below screenshot allows you to add a directory to the list. Could this also be used for telling this HCL plugin where to look for files?

image

VladRassokhin commented 3 years ago

Thanks for info, I'll think about possible solutions, though don't expect them quickly

MrZablah commented 2 years ago

Is there any update on this? I have the same issue and I will love to have this.

Since for know it will give me an error if I don't use the flag: //noinspection MissingModule