我正在关注这个 HashiCorp tutorial,我在 Windows 11 上使用 Chocolatey 安装了 terraform 1.8.0。我创建了给定的
main.tf
文件,当我运行 terraform init
并收到此错误时:
c:\x\src\terraform\docker>terraform init
Initializing the backend...
Initializing provider plugins...
- Finding kreuzwerker/docker versions matching "~> 3.0.1"...
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider
│ kreuzwerker/docker: could not connect to registry.terraform.io: failed to
│ request discovery document: Get
│ "https://registry.terraform.io/.well-known/terraform.json": read tcp
│ [2a01:e34:ecb9:6700:d94f:f715:3ca2:d1e]:49939->[2600:9000:262b:2c00:16:1aa3:1440:93a1]:443:
│ wsarecv: An existing connection was forcibly closed by the remote host.
所以我检查了
https://registry.terraform.io/.well-known/terraform.json
URL,在浏览器(Chrome 和 Firefox)上我可以检索 .json 文件,但不能使用 curl
或 wget
:
c:\x\src\terraform\docker>curl https://registry.terraform.io/.well-known/terraform.json
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (35) Send failure: Connection was reset
c:\x\src\terraform\docker>wget https://registry.terraform.io/.well-known/terraform.json
--2024-04-12 22:54:14-- https://registry.terraform.io/.well-known/terraform.json
Resolving registry.terraform.io (registry.terraform.io)... 2600:9000:262b:2c00:16:1aa3:1440:93a1, 2600:9000:262b:1a00:16:1aa3:1440:93a1, 2600:9000:262b:b400:16:1aa3:1440:93a1, ...
Connecting to registry.terraform.io (registry.terraform.io)|2600:9000:262b:2c00:16:1aa3:1440:93a1|:443... connected.
Unable to establish SSL connection.
curl
命令显示发送失败:连接已重置,wget
显示无法建立 SSL 连接。因此,所有三个命令行工具都失败(在 CMD 和 PowerShell 中)此 https 请求到 registry.terraform.io
,而浏览器成功执行了此操作。
我怀疑我的 Windows 11 系统上有什么东西,可能是证书?我知识不够,欢迎任何调查此问题的建议。
另请注意,我在该 Windows 主机内的 VirtualBox 中运行了 Debian 系统,安装了 terraform,并且 terraform init 命令刚刚起作用,这再次表明 Windows 系统是这里的罪魁祸首。
回答我自己的问题:进一步谷歌搜索后,我找到了在网络适配器上禁用 IPv6 的建议,这解决了问题。