Terraform 系统找不到指定的路径

Terraform The system cannot find the path specified

What specific configuration or syntax changes must be made in order to resolve the The system cannot find the path specified. error that terraform is throwing when it tries to load a provider from a local mirror?

问题

terraform 提供程序的本地文件系统镜像在自动化程序中重新使用。

  1. 在尝试在 2 分钟内下载模块的第三个模块第三次使用同一提供程序期间,控制台打印出 The system cannot find the path specified.

  2. 从同一个本地文件系统镜像请求同一个提供程序的前两次在引发此错误之前的几分钟内成功。

  3. 当调用程序在每次请求前休眠 360 秒以避免可能的锁定原因时,问题仍然存在。延迟 6 分钟并不能避免问题。

提供商 EXE 文件存在

当我们在 Windows 资源管理器中查看时,确实会出现 terraform-provider-aws_v3.22.0_x5.exe 提供程序文件。然后,我们右击exe文件,打开属性window,位置和文件名给出为:

C:\projects\TERRAF~1DEC2~1\TERRAF~2\CALLS-~1\INSTAN~1\SUBNET~1\DEMO-D~1\TERRAF~1\PROVID~1\REGIST~1.IO\HASHIC~1\aws2~1.0\WINDOW~1  

然后当我们运行一个dir命令去浏览目录的时候,我们也看到如下:

C:\path\to\some\directory>dir C:\projects\TERRAF~1DEC2~1\TERRAF~2\CALLS-~1\INSTAN~1\SUBNET~1\DEMO-D~1\TERRAF~1\PROVID~1\REGIST~1.IO\HASHIC~1\aws2~1.0\WINDOW~1
 Volume in drive C is Windows
 Volume Serial Number is DAB2-5285

 Directory of C:\projects\TERRAF~1DEC2~1\TERRAF~2\CALLS-~1\INSTAN~1\SUBNET~1\DEMO-D~1\TERRAF~1\PROVID~1\REGIST~1.IO\HASHIC~1\aws2~1.0\WINDOW~1

12/29/2020  01:36 PM    <DIR>          .
12/29/2020  01:36 PM    <DIR>          ..
12/29/2020  01:36 PM       175,883,264 terraform-provider-aws_v3.22.0_x5.exe
           1 File(s)    175,883,264 bytes
           2 Dir(s)  736,395,243,520 bytes free

完整的堆栈跟踪

terraform命令完整的TRACE输出如下:

Initializing provider plugins...
- Finding latest version of hashicorp/aws...
2020/12/29 13:36:35 [TRACE] getproviders.SearchLocalDirectory: C:\path\to\terraform\providers is a symlink to C:\path\to\terraform\providers
2020/12/29 13:36:35 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/aws v3.22.0 for windows_amd64 at C:\path\to\terraform\providers\registry.terraform.io\hashicorp\aws.22.0\windows_amd64
2020/12/29 13:36:35 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/http v2.0.0 for windows_amd64 at C:\path\to\terraform\providers\registry.terraform.io\hashicorp\http.0.0\windows_amd64
2020/12/29 13:36:35 [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/hashicorp/aws v3.22.0 from C:\path\to\terraform\providers\registry.terraform.io\hashicorp\aws.22.0\windows_amd64
- Installing hashicorp/aws v3.22.0...
2020/12/29 13:36:35 [TRACE] providercache.fillMetaCache: scanning directory .terraform\providers
2020/12/29 13:36:35 [TRACE] getproviders.SearchLocalDirectory: .terraform\providers is a symlink to .terraform\providers
2020/12/29 13:36:35 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/aws v3.22.0 for windows_amd64 at .terraform\providers\registry.terraform.io\hashicorp\aws.22.0\windows_amd64
2020/12/29 13:36:35 [TRACE] providercache.fillMetaCache: error while scanning directory .terraform\providers: cannot search .terraform\providers\registry.terraform.io\hashicorp\aws.22.0\windows_amd64\terraform-provider-aws_v3.22.0_x5.exe: CreateFile .terraform\providers\registry.terraform.io\hashicorp\aws.22.0\windows_amd64\terraform-provider-aws_v3.22.0_x5.exe: The system cannot find the path specified.

Error: Failed to install provider

@JohnHanley 的建议

根据@JohnHanley 在评论中的建议,我们将 `` 注册表项重置为 1,然后打开 Windows CMD 的另一个实例,导航到同一目录,然后 运行 相同的自动化程序。

程序现在和以前一样停在了同一个地方,但是这次程序肯定挂了,而不是明确地抛出错误。

这是到挂起为止的新控制台输出:

Initializing provider plugins...
- Finding latest version of hashicorp/aws...
2020/12/29 15:39:21 [TRACE] getproviders.SearchLocalDirectory: C:\path\to\terraform\providers is a symlink to C:\path\to\terraform\providers
2020/12/29 15:39:21 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/aws v3.22.0 for windows_amd64 at C:\path\to\terraform\providers\registry.terraform.io\hashicorp\aws.22.0\windows_amd64
2020/12/29 15:39:21 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/http v2.0.0 for windows_amd64 at C:\path\to\terraform\providers\registry.terraform.io\hashicorp\http.0.0\windows_amd64
2020/12/29 15:39:21 [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/hashicorp/aws v3.22.0 from C:\path\to\terraform\providers\registry.terraform.io\hashicorp\aws.22.0\windows_amd64
- Installing hashicorp/aws v3.22.0...

错误消息表明存在 MAX_PATH 问题。一个附带问题是该路径正在使用 DOS 命名空间。解决方案是重新组织目录结构以缩短路径或使用 UNC 路径。

对于 DOS 命名空间,应用程序通常被编码为支持最大长度为 255 个字符。对于 LONG 命名空间,最大长度为 260 个字符,其中目录部分不能超过 MAX_PATH - 12 (248) 个字符。终止 NULL 占用一个字符。

Enable Long Paths in Windows 10, Version 1607, and Later