Hi @radag87
You are right that we don’t provide enough actionable details and that’s something I’d like to fix.
The expectation of the language server (and in turn the VS Code extension) is that there is a root module somewhere in the hierarchy of the folder opened in VS Code. Root module in this context basically means a directory of *.tf files has been terraform init-ed.
This warning message in particular comes from the language server and I suppose it could suggest you to run terraform init. Would that be helpful?
Ideally we’d like to go further and let VS Code prompt you to terraform init a directory, but that means we need to understand what directories are the right candidates for init-able root modules. i.e. we don’t know yet where to terraform init. What the server can see is a hierarchy of many folders, many of which may have *.tf files in them, so in theory any of them are init-able.
Thanks for the feedback. The issue does not seem to be related to the absence or presence of a .terraform directory. Even after I run terraform init, the message appears. At most it is an annoyance. Everything else seems to be working.
@daps-us That certainly isn’t intention and shouldn’t be happening, so I would consider that a bug.
Do you mind sharing some details about the hierarchy of the folder you open in the editor? e.g. tree -a -d . output would be useful, and/or log output as per our Troubleshooting instructions.
Is there a way to just suppress these warning messages in VScode?
I cloned a terragrunt repo and when navigating between files, it causes one of these popups every time i open a new .tf file.
Thanks for sharing the tree - that is useful. A few more questions so I can interpret this in the right context:
Are all these nested submodules referenced from the root module (e.g. via module { source = "./module/ccoe/modules/backup/awsbackup")?
Alternatively do they reference each other (e.g. compute/lambda references compute/lambda-permission)?
Which files trigger the warning - i.e. are you opening *.tf files just within the root folder or inside the submodules too? Does it happen in both cases or either of them?
If you’re getting the warning for all files within the hierarchy then I suspect the problem is not related to the hierarchy. In such case I’d recommend collecting some logs as they may shed the light on why the initialized root module isn’t being picked up, which may be for a number of reasons:
I had not installed terraform-ls separately. I only used whatever vscode installed. I am installing it now.
You should not need to install the language server separately in order to modify how it’s being launched, you can just modify the args in the settings, e.g.
All the nested submodules are referenced from the root module.
The modules to do reference each other.
I am only opening .tf files in the root directory.
10020 [07/10/20 16:10] $ which terraform
/Users/raul/.local/bin/terraform
2020/07/10 16:14:55 root_module_manager.go:138: looking up
/Users/raul/repos/aws/resolver-inbound in module references of /Users/raul/repos/aws/ccoe-unbound
2020/07/10 16:14:55 server.go:342: Posting server notification “window/showMessage” {“type”:2,“message”:“No root module found for main.tf. Functionality may be limited. You may need to run terraform init”}
2020/07/10 16:15:04 server.go:469: Received 1 new requests
2020/07/10 16:15:04 server.go:165: Processing 1 requests
2020/07/10 16:15:04 server.go:223: Checking request for “textDocument/didClose”: {“textDocument”:{“uri”:“file:///Users/raul/repos/aws/resolver-inbound/main.tf”}}
2020/07/10 16:15:04 rpc_logger.go:29: Incoming notification for “textDocument/didClose”: {“textDocument”:{“uri”:“file:///Users/raul/repos/aws/resolver-inbound/main.tf”}}
2020/07/10 16:15:04 server.go:469: Received 1 new requests
2020/07/10 16:15:04 server.go:165: Processing 1 requests
2020/07/10 16:15:04 server.go:223: Checking request for “textDocument/didOpen”: {“textDocument”:{“uri”:“file:///Users/raul/repos/aws/resolver-inbound/outputs.tf”,“languageId”:“terraform”,“version”:1,“text”:“output "account_id" {\n value = data.aws_caller_identity.current.account_id\n}\noutput "caller_arn" {\n value = data.aws_caller_identity.current.arn\n}\noutput "caller_user" {\n value = data.aws_caller_identity.current.user_id\n}\noutput "sg_id" {\n value = aws_security_group.sg.id\n}\noutput "sg_allow_tcp_id" {\n value = aws_security_group_rule.allow_dns_tcp.id\n}\noutput "sg_allow_udp_id" {\n value = aws_security_group_rule.allow_dns_udp.id\n}\n”}}
2020/07/10 16:15:04 rpc_logger.go:29: Incoming notification for “textDocument/didOpen”: {“textDocument”:{“uri”:“file:///Users/raul/repos/aws/resolver-inbound/outputs.tf”,“languageId”:“terraform”,“version”:1,“text”:“output "account_id" {\n value = data.aws_caller_identity.current.account_id\n}\noutput "caller_arn" {\n value = data.aws_caller_identity.current.arn\n}\noutput "caller_user" {\n value = data.aws_caller_identity.current.user_id\n}\noutput "sg_id" {\n value = aws_security_group.sg.id\n}\noutput "sg_allow_tcp_id" {\n value = aws_security_group_rule.allow_dns_tcp.id\n}\noutput "sg_allow_udp_id" {\n value = aws_security_group_rule.allow_dns_udp.id\n}\n”}}
2020/07/10 16:15:04 root_module_manager.go:138: looking up /Users/raul/repos/aws/resolver-inbound in module references of /Users/raul/repos/aws/ccoe-unbound
2020/07/10 16:15:04 server.go:342: Posting server notification “window/showMessage” {“type”:2,“message”:“No root module found for outputs.tf. Functionality may be limited. You may need to run terraform init”}
It looks like the information I did not provide may be part of the problem. I have three git projects in the vs code workspace. It appears that the language server is treating them as if they were one common set of code.
After removing the two other projects from the workspace, then the language server stops complaining. I understand the behavior now.
I don’t know if this should be considered a bug or an enhancement request, but it would be useful if I did not have to have one workspace per project as it makes refactoring trickier.
I’m seeing this as well when I open any tf file in a submodule. It’s very annoying, as it gets in the way of my console in vscode. Is there any way I can filter this message or check completely? It would really be nice if it was an optional warning, or could have functionality to click on the warning, and say to ignore forever.
Ensure the installed versions of terraform and vs code is the latest one.
The error should disappear after installing the newest versions and running terraform init command.
The point is that when developing a module that will be referenced in other repositories I don’t want to initialise a terraform state for the module itself… and I don’t want to be nagged about it every time I open a file either.