You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run terraform init in the terraform/cloudflare directory:
cd terraform/cloudflare
terraform init
Open terraform/cloudflare/main.tf in VSCode.
Hover over the "cloudflare" part of provider "cloudflare" {} in main.tf and observe that the provider is reported as version 5.1.0.
Run ./random_tree.sh to generate a random directory structure with 1000 100kB files in ./random_tree.
Cmd-Shift-P to open the VSCode command palette and type "Developer: Reload Window" and select it.
Hover over the "cloudflare" part of provider "cloudflare" {} in main.tf and observe that the provider is reported as version 4.51.0.
In addition, observe that the following errors are reported on the cloudflare_zone.zone resource:
Required attribute "account_id" not specified: An attribute named "account_id" is required hereTerraform
Required attribute "zone" not specified: An attribute named "zone" is required hereTerraform
Unexpected attribute: An attribute named "account" is not expected hereTerraform
If you want, remove the ./random_tree directory to clean up:
rm -rf ./random_tree
At this point, if you reload VSCode again, the correct provider version (5.1.0) will be reported and the errors will go away
Expected Behavior
See above (version 4.51.0 of the Cloudflare provider is used).
Actual Behavior
See above (version 5.1.0 of the Cloudflare provider should be used).
This is not reproducible if main.tf is located in the root of the repository.
The size of the files (FILE_SIZE in random_tree.sh) has no bearing on success/failure.
The number of files (NUM_FILES in random_tree.sh) does have a bearing on success/failure. If I set it to a low number like 10, the correct provider is always loaded. At about 50 files, things work maybe 50% of the time. At 1000 files (the default in my script), things fail reliably 100% of the time.
When the right provider is loaded, I see the following in "Output" -> "HashiCorp Terraform" in VSCode: provider_schema.go:126: PSS: adding local schema (/Users/nathan/git/terraform-vscode-schema-repro/terraform/cloudflare, registry.terraform.io/cloudflare/cloudflare): 0x1400028e420
When the incorrect provider is loaded, I see the following instead: provider_schema.go:604: preloaded schema for registry.terraform.io/cloudflare/cloudflare 4.51.0 in 18.298417ms
This feels very much like a race condition, though I have no idea why the number of files in a directory would have anything to do with it.
It's possible this is a bug in terraform-ls instead. From reading https://github.com/hashicorp/terraform-ls/blob/main/docs/schema.md, I understand that the language server contains pre-bundled copies of some provider schemas, which would explain the discrepancy (5.1.0 is very new and isn't included in either this extension or terraform-ls). Let me know if I should file this in that repository instead, but I was only able to reproduce this in the context of VSCode.
Workarounds
Removing most of the files in my repository fixes things; that's obviously a non-starter.
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
The text was updated successfully, but these errors were encountered:
nwalters512
changed the title
Incorrect provider version loaded when directory contains a large, deep directory structure
Incorrect provider version loaded when project contains a large, deep directory structure
Feb 20, 2025
Extension Version
2.34.2
VS Code Version
Version: 1.97.2 (Universal)
Commit: e54c774e0add60467559eb0d1e229c6452cf8447
Date: 2025-02-12T23:20:35.343Z (1 wk ago)
Electron: 32.2.7
ElectronBuildId: 10982180
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Darwin arm64 24.3.0
Operating System
macOS 15.3.1 (24D70)
Terraform Version
Terraform v1.10.5 on darwin_arm64
Steps to Reproduce
Reproduction repository located here: https://github.com/nwalters512/terraform-vscode-schema-repro
Clone this repository:
Open the repository in VSCode:
Run
terraform init
in theterraform/cloudflare
directory:cd terraform/cloudflare terraform init
Open
terraform/cloudflare/main.tf
in VSCode.Hover over the
"cloudflare"
part ofprovider "cloudflare" {}
inmain.tf
and observe that the provider is reported as version5.1.0
.Run
./random_tree.sh
to generate a random directory structure with 1000 100kB files in./random_tree
.Cmd-Shift-P to open the VSCode command palette and type "Developer: Reload Window" and select it.
Hover over the
"cloudflare"
part ofprovider "cloudflare" {}
inmain.tf
and observe that the provider is reported as version4.51.0
.In addition, observe that the following errors are reported on the
cloudflare_zone.zone
resource:If you want, remove the
./random_tree
directory to clean up:At this point, if you reload VSCode again, the correct provider version (
5.1.0
) will be reported and the errors will go awayExpected Behavior
See above (version
4.51.0
of the Cloudflare provider is used).Actual Behavior
See above (version
5.1.0
of the Cloudflare provider should be used).Terraform Configuration
Project Structure
Gist
No response
Anything Else?
Some things I noticed while testing:
main.tf
is located in the root of the repository.FILE_SIZE
inrandom_tree.sh
) has no bearing on success/failure.NUM_FILES
inrandom_tree.sh
) does have a bearing on success/failure. If I set it to a low number like 10, the correct provider is always loaded. At about 50 files, things work maybe 50% of the time. At 1000 files (the default in my script), things fail reliably 100% of the time.provider_schema.go:126: PSS: adding local schema (/Users/nathan/git/terraform-vscode-schema-repro/terraform/cloudflare, registry.terraform.io/cloudflare/cloudflare): 0x1400028e420
provider_schema.go:604: preloaded schema for registry.terraform.io/cloudflare/cloudflare 4.51.0 in 18.298417ms
This feels very much like a race condition, though I have no idea why the number of files in a directory would have anything to do with it.
It's possible this is a bug in
terraform-ls
instead. From reading https://github.com/hashicorp/terraform-ls/blob/main/docs/schema.md, I understand that the language server contains pre-bundled copies of some provider schemas, which would explain the discrepancy (5.1.0 is very new and isn't included in either this extension orterraform-ls
). Let me know if I should file this in that repository instead, but I was only able to reproduce this in the context of VSCode.Workarounds
Removing most of the files in my repository fixes things; that's obviously a non-starter.
References
No response
Help Wanted
Community Note
The text was updated successfully, but these errors were encountered: