Language server references variables of a parent module instead of sub-module
Closed this issue · 5 comments
Language Server Version
v0.34.0
Terraform Version
Terraform v1.9.1 on linux_amd64
Client Version
neovim 0.10.0
Terraform Configuration
module "project_services" {
source = "terraform-google-modules/project-factory/google//modules/project_services"
version = "~> 15.0"
#billing_account = var.billing_account
project_id = var.project_id
#name = var.project_id
activate_apis = local.services
disable_services_on_destroy = false
depends_on = [
google_project.main
]
providers = {
google = google.no_user_project_override
google-beta = google.no_user_project_override
}
}
Steps to Reproduce
- Open the file with above code
- Language server will report missing
billing_account
andname
attributes
Looking at the variables of the sub-module, there are no billing_account
or name
variables declared: https://github.com/terraform-google-modules/terraform-google-project-factory/blob/v15.0.1/modules/project_services/variables.tf
They are present in the root module variables file:
- https://github.com/terraform-google-modules/terraform-google-project-factory/blob/9ac04a6868cadea19a5c016d4d0a4ae35d378b05/variables.tf#L41
- https://github.com/terraform-google-modules/terraform-google-project-factory/blob/9ac04a6868cadea19a5c016d4d0a4ae35d378b05/variables.tf#L64
But since we're explicitly using the sub-module, the language server shouldn't report these as missing.
In fact, even looking at the variable definitions, they're referring to root module variables, instead of sub-module:
So this https://github.com/terraform-google-modules/terraform-google-project-factory/blob/9ac04a6868cadea19a5c016d4d0a4ae35d378b05/variables.tf#L47 is used instead of https://github.com/terraform-google-modules/terraform-google-project-factory/blob/9ac04a6868cadea19a5c016d4d0a4ae35d378b05/modules/project_services/variables.tf#L18
This only started happening in the lastest version of the language server, as far as I can tall.
Expected Behavior
Parent module variables shouldn't be reported as missing
Actual Behavior
Parent module variables are reported as missing
Gist
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
FYI, I tried to downgrade to 0.33.0 and the issue is gone. So this was definitely introduced in 0.34.0
Hi @serpro69, thanks for the detailed report! I'm able to reproduce the problem.
This bug was probably introduced in #1760. Sorry for the inconvenience.
We have two ways to get the module schema for registry modules:
- we use the local installation of a module – seems to work as expected
- we fetch the module metadata from https://registry.terraform.io/
The API response for 2) contains the inputs and outputs for the terraform-google-modules/project-factory/google
and all its submodules. But instead of using the appropriate ones for modules/project_services
, we default to the top-level ones.
I'll look into a fix
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.