hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.69k stars 9.55k forks source link

WSL2 terminal running VSCode, first terraform init would fail, consequent terraform init works. If run WSL2 outside of VSCode, terraform init always works. #31727

Closed jye-aviatrix closed 1 year ago

jye-aviatrix commented 2 years ago

Terraform Version

Terraform v1.2.8
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v4.28.0
+ provider registry.terraform.io/hashicorp/http v3.1.0

Terraform Configuration Files

module "vgw-strongwan-site-to-site-vpn" {
  source  = "jye-aviatrix/vgw-strongwan-site-to-site-vpn/aws"
  version = "1.0.0"
  key_name  = "ec2-key-pair"
}

output "strongwan" {
  value = module.vgw-strongwan-site-to-site-vpn
}

Debug Output

https://gist.github.com/jye-aviatrix/87aad49e53795860b25dd74d4a421c9b

Expected Behavior

terraform init would work in first try

Actual Behavior

WSL2 terminal running VSCode, first terraform init would fail, consequent terraform init works. If run WSL2 outside of VSCode, terraform init always works.

Steps to Reproduce

terraform init

Additional Context

VSCode Version: 1.70.2 (user setup) Commit: e4503b30fc78200f846c62cf8091b76ff5547662 Date: 2022-08-16T05:35:13.448Z Electron: 18.3.5 Chromium: 100.0.4896.160 Node.js: 16.13.2 V8: 10.0.139.17-electron.0 OS: Windows_NT x64 10.0.22000

WSL2 version: 5.10.102.1-microsoft-standard-WSL2

References

No response

kmoe commented 2 years ago

Interesting report, thank you. It looks like the error is thrown by git itself:

/usr/bin/git exited with -1: Cloning into '.terraform/modules/vgw-strongwan-site-to-site-vpn'...
│ BUG: refs/files-backend.c:2956: initial ref transaction called with existing refs

Please therefore do the following in order to determine which of the various pieces are going wrong here.

  1. Try running terraform init the same way inside WSL, but with a different module (not vgw-strongwan-site-to-site-vpn).
  2. Try the following command inside WSL instead of terraform init: git clone https://github.com/jye-aviatrix/terraform-aws-vgw-strongwan-site-to-site-vpn . && git checkout 1.0.0

Please also supply your version of git.

In the meantime, some workarounds that could conceivably fix this:

I'm curious as to why the "Error: Failed to download module" is printing twice. That's the only thing here that suggests to me this may be a bug in Terraform Core - otherwise the likely suspects are git, go-getter, and the peculiarities of a VSCode-on-WSL-on-Windows setup.

crw commented 1 year ago

Hi @jye-aviatrix, I'm cleaning up old issues and I see this one did not receive a response. I am going to close this issue now, please let me know if you believe this action to be taken in error. Thanks!

github-actions[bot] commented 11 months ago

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.