Cannot locate module locally
See original GitHub issuePrerequisites
- Ensure you have latest version of plugin installed
- Search for possible issue duplicates - related to closed issue https://github.com/VladRassokhin/intellij-hcl/issues/170
Installation details
- IDE version (
Help->About->Copy to Clipboard
)IntelliJ IDEA 2021.2 (Ultimate Edition) Build #IU-212.4746.92, built on July 27, 2021 Runtime version: 11.0.11+9-b1504.13 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 10.15.7 GC: ParNew, ConcurrentMarkSweep Memory: 4029M Cores: 8 Registry: scala.erase.compiler.process.jdk.once=false Non-Bundled Plugins: org.intellij.plugins.hcl (0.7.14), mobi.hsz.idea.gitignore (4.2.0), name.kropp.intellij.makefile (212.4746.52), org.toml.lang (0.2.152.4026-212), org.jetbrains.plugins.hocon (2021.1.0), intellij.prettierJS (212.4746.57), Pythonid (212.4746.96), org.jetbrains.plugins.go (212.4746.92), org.intellij.scala (2021.2.15), pro.bashsupport (2.0.4.212) Kotlin: 212-1.5.10-release-IJ4746.92
- intellij-hcl plugin version (
Settings->Plugins
) -0.7.14
- Terraform version (
terraform -v
) -v1.0.10
(darwin_amd64
)
Terraform Configuration Files
module "iam" {
source = "s3::https://s3.amazonaws.com/path/to/module.zip"
}
And here is the project folder (including .terraform
cache):
.
├── .terraform
│ ├── modules
│ │ ├── iam
│ │ │ ├── Makefile
│ │ │ ├── main.tf
│ │ │ ├── modules
│ │ │ │ ├── iam
│ │ │ │ │ ├── .terraform.lock.hcl
│ │ │ │ │ ├── main.tf
│ │ │ │ │ ├── outputs.tf
│ │ │ │ │ └── variables.tf
│ │ │ │ ├── local-data
│ │ │ │ │ └── outputs.tf
│ │ │ │ └── path
│ │ │ │ ├── outputs.tf
│ │ │ │ └── variables.tf
│ │ │ ├── output.tf
│ │ │ ├── policies
│ │ │ │ └── assume-role
│ │ │ │ └── codebuild.json
│ │ │ ├── variables.tf
│ │ │ └── versions.tf
│ │ ├── iam.path.path
│ │ │ ├── go.mod
│ │ │ ├── go.sum
│ │ │ ├── infra
│ │ │ ├── output.tf
│ │ │ ├── readme.md
│ │ │ └── variables.tf
│ │ ├── iam.session
│ │ │ ├── Makefile
│ │ │ ├── main.tf
│ │ │ ├── modules
│ │ │ │ └── local-data
│ │ │ │ └── outputs.tf
│ │ │ ├── outputs.tf
│ │ │ └── versions.tf
│ │ └── modules.json
│ └── providers
│ └── registry.terraform.io
│ └── hashicorp
│ └── aws
│ └── 3.58.0
│ └── darwin_amd64
│ └── terraform-provider-aws_v3.58.0_x5
├── .terraform.lock.hcl
└── main.tf
Exception
N/A
Expected Behavior
The HCL plugin should be able to reference any module cached in the ./.terraform
in the current directory. We are using Terraform inside of a monorepo, so we have several directories scattered around with Terraform configuration. I have noticed in some project folders we do not have this issue and in others we do. It seems to happen most often within sub-modules (e.g. ./modules/bar
, relative to the project root), or when referencing sub-folders of a module, for example:
module "bar" {
source = "s3::https://s3.amazonaws.com/path/to/module.zip//path/to/sub-module"
}
Actual Behavior
Cannot locate module locally: Terraform Module 'iam' with source 's3::https://s3.amazonaws.com/path/to/module.zip' directory not found locally, use `terraform get` to fetch modules.
The module exists, of course, and is downloaded and cached in the .terraform
folder. Performing Terraform CLI commands in the directory will succeed. It’s just a problem with the plugin cache.
. <-- in this folder the module was resolved, and it also resolved it in the sub-folder
├── Makefile
├── main.tf
├── modules
│ ├── iam <-- the folder where the module cannot be resolved
│ │ └── main.tf
│ └── meta
│ └── outputs.tf
├── output.tf
├── readme.md
├── variables.tf
└── versions.tf
In the example we are downloading the module from S3, but it shouldn’t matter what the source is. Notably, though, I haven’t seen this happen with a local module reference (e.g. source = "../../path/to/module"
).
Steps to Reproduce
See the comment below https://github.com/VladRassokhin/intellij-hcl/issues/365#issuecomment-981972598
Issue Analytics
- State:
- Created 2 years ago
- Reactions:33
- Comments:18
Top GitHub Comments
Not sure if it’s the same cause but had the same issue with Terraform 1.1.0. They changed how they store the
Source
in.terraform/modules/modules.json
causing my issue. See https://github.com/hashicorp/terraform/pull/28854. Looks like the plugin reads that file.Fixed it by making sure the
Source
field in.terraform/modules/modules.json
matches exactly thesource
in the TF file. If doesn’t match, modify it for all the modules in that file and restart the IDE (or close and open the file).Example for an official module: change
registry.terraform.io/terraform-aws-modules/vpc/aws
toterraform-aws-modules/vpc/aws
I’m using PyCharm 2021.3 and version 0.7.14 of the plugin. I have also a monorepo with multiple Terraform projects!
Alternativlity, you can prepend the source URI in your
main.tf
withregistry.terraform.io/
. Not including it is just a short hand way of indicating that the module is hosted on the Terraform registry. By prepending the registry in your source reference you don’t have to touch the files in the cache.