Terraform:无法在 M1 Pro 上查询可用的提供程序包



我正在使用新的苹果 M1 pro,当我运行 terraform init 时,我无法查询可用提供程序包错误

错误

Reusing previous version of newrelic/newrelic from the dependency lock file
╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider hashicorp/aws: locked provider registry.terraform.io/hashicorp/aws 2.70.0 does not match configured version constraint ~>
│ 3.53.0; must use terraform init -upgrade to allow selection of new versions
╵
╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider ns1-terraform/ns1: could not connect to registry.terraform.io: Failed to request discovery document: Get
│ "https://registry.terraform.io/.well-known/terraform.json": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
╵
╷
│ Error: Incompatible provider version
│ 
│ Provider registry.terraform.io/hashicorp/template v2.2.0 does not have a package available for your current platform, darwin_arm64.
│ 
│ Provider releases are separate from Terraform CLI releases, so not all providers are available for all platforms. Other versions of this provider may have different platforms supported.
╵
╷
│ Error: Failed to install provider
│ 
│ Error while installing newrelic/newrelic v2.25.0: could not query provider registry for registry.terraform.io/newrelic/newrelic: failed to retrieve authentication checksums for provider: the
│ request failed after 2 attempts, please try again later: Get
│ "https://objects.githubusercontent.com/github-production-release-asset-2e65be/93446098/7aca5d90-9fc0-43cd-946b-46f556c2bbfa?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20211215%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20211215T180026Z&X-Amz-Expires=300&X-Amz-Signature=01f9b195e6e9355253a588d09c73a78f499e6d1b1f2014f921e749b0da9c4c4e&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=93446098&response-content-disposition=attachment%3B%20filename%3Dterraform-provider-newrelic_2.25.0_SHA256SUMS&response-content-type=application%2Foctet-stream":
│ net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

这组错误似乎同时描述了三个独立的问题:

您的 Terraform
  • 配置声明它需要与版本约束~> 3.53.0匹配的hashicorp/aws提供程序版本,该版本与>= 3.53.0, < 3.34.0相同,与在以前的 Terraform 运行中选择的版本2.70.0不匹配。

    如果有意更改版本约束以升级提供程序,则可以按照该特定错误中的建议进行操作,并运行terraform init -upgrade以选择与版本约束匹配的每个提供程序的最新版本。或者,您可以将更改还原为版本约束,以便配置接受2.70.0作为合适的版本,然后继续使用该版本。

  • 您的配置取决于旧版提供商hashicorp/template,不幸的是,在Apple推出基于Apple硅的产品之前,该提供商已达到生命周期的终点,因此该特定提供商没有任何可以在M1 Mac上运行的软件包。

    您可以通过在 Rosetta 2 仿真下运行 Terraform CLI 的darwin_amd64版本来解决此问题,这反过来会导致 Terraform 也在 Rosetta 2 仿真中安装和运行提供程序的darwin_amd64版本。

    对于现代 Terraform,您通常应该按照文档中的建议使用templatefile函数而不是已弃用的template_file数据源,但我建议您确保能够先使用 Rosetta 2 仿真使用当前配置,然后再修改它以删除已弃用的提供程序,因为这将允许您比较更改前后的行为,从而确保您没有无意中更改配置行为。

    但是,一旦不再使用已弃用的提供程序,您应该能够使用 Terraform 的本机 Apple Silicon 版本(您已经在使用的darwin_arm64版本)进行此配置的未来工作,因为此提供程序是在此处生成该特定错误消息的唯一提供程序。

  • 最后,Terraform 在尝试自动安装提供程序时似乎遇到了一些网络连接问题。似乎这并不是完全无法访问Terraform 注册表和托管在 GitHub 上的提供商包,因为 Terraform 显然能够查询registry.terraform.io以了解哪些版本的hashicorp/template可用,但有些请求没有成功,所以也许您正在通过公司防火墙或类似的过滤访问互联网,这使得一部分请求失败, 出于某种原因。

由于这最终至少同时是三个问题,如果您对这些答案中的任何一个有任何进一步的问题,那么我建议您开始一个新的 Stack Overflow 问题,包括必要的任何附加上下文,因为这将有望让想要回答的人有更多的上下文,从而为您提供更可行的解决方案。

我也在使用带有M1芯片的Macbook,我一直面临同样的错误。为了修复,我不得不卸载terraform"brew卸载terraform",按照这些说明 https://benobi.one/posts/running_brew_on_m1_for_x86/,运行"ibrew install hashicorp/tap/terraform"。

尽管"地形版本"将提供与以前相同的输出,但它现在可以工作了。至少对我来说。希望这对某人有所帮助!

最新更新