Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vscode always complains This module is not yet installed error in submodules #1724

Open
1 task
islishude opened this issue Mar 28, 2024 · 1 comment
Open
1 task
Labels
bug Something isn't working

Comments

@islishude
Copy link

Extension Version

v2.29.5

VS Code Version

Version: 1.87.2 (Universal)
Commit: 863d2581ecda6849923a2118d93a088b0745d9d6
Date: 2024-03-08T15:21:31.043Z
Electron: 27.3.2
ElectronBuildId: 26836302
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Darwin arm64 23.4.0

Operating System

14.4.1 (23E224)

Terraform Version

Terraform v1.7.5 on darwin_arm64

Steps to Reproduce

$ cat version.tf                                                                        
terraform {
  required_version = "~> 1.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}
$ cat modules/test/main.tf
terraform {
  required_version = "~> 1.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

variable "cidr" {
  type        = string
  description = "vpc cidr"
}

variable "public_subnet" {
  type        = list(string)
  description = "public subnet cidr"
}

variable "name" {
  type        = string
  description = "vpc name"
}

data "aws_availability_zones" "available" {
  filter {
    name   = "opt-in-status"
    values = ["opt-in-not-required"]
  }
}

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "~> 5.0"

  name = var.name

  cidr = var.cidr
  azs  = slice(data.aws_availability_zones.available.names, 0, 3)

  public_subnets = var.public_subnet

  enable_dns_hostnames    = true
  map_public_ip_on_launch = true

  public_subnet_tags = {
    "kubernetes.io/cluster/${var.name}" = "shared"
    "kubernetes.io/role/elb"            = 1
  }

  private_subnet_tags = {
    "kubernetes.io/cluster/${var.name}" = "shared"
    "kubernetes.io/role/internal-elb"   = 1
  }
}
$ tf init                                                                                                                                        
Initializing the backend...
Initializing modules...
- use1 in modules/test
Downloading registry.terraform.io/terraform-aws-modules/vpc/aws 5.7.0 for use1.vpc...
- use1.vpc in .terraform/modules/use1.vpc

Initializing provider plugins...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Installing hashicorp/aws v5.42.0...
- Installed hashicorp/aws v5.42.0 (signed by HashiCorp)

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
$ tf validate
Success! The configuration is valid.

Expected Behavior

there should be no errors.

Actual Behavior

image

I have to run tf init in the submodules to fix the error

Terraform Configuration

No response

Project Structure

No response

Gist

No response

Anything Else?

No response

Workarounds

No response

References

No response

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@islishude islishude added the bug Something isn't working label Mar 28, 2024
@dbanck
Copy link
Member

dbanck commented Mar 28, 2024

Hi @islishude , Thanks for raising the issue and sorry for the trouble! I'm able to reproduce the bug.

When we run terraform validate on save, we use the folder of the current file as base. This would be the same as running terraform validate in modules/test/ which results in the same error you're seeing in VS Code.

issue1724/modules/test ❯ terraform validate
╷
│ Error: Module not installed
│
│   on main.tf line 34:
│   34: module "vpc" {
│
│ This module is not yet installed. Run "terraform init" to install all modules required by this configuration.
╵

It's difficult for us to quickly determine the root module when we run validation on save, so we default to the current directory

The only way to get rid of that error today is to disable validation on safe:

"terraform.experimentalFeatures.validateOnSave": false,

This still leaves you with the enhanced editor validation, which covers many similar cases as terraform validate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants