Terraform:解决“没有可用版本与给定约束匹配”错误

Hal*_*lil 3 amazon-web-services terraform infrastructure-as-code

我正在尝试更新 hashcorp/aws 提供商版本。

我添加了包含以下内容的 terraform.tf 文件:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

后来我尝试使用以下方法更新模块:

terraform init -upgrade
Run Code Online (Sandbox Code Playgroud)

然而,我已经开始明白:

Could not retrieve the list of available versions for provider hashicorp/aws: no available releases match the given constraints >= 2.0.0, ~> 3.27, ~> 4.0
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题呢?

Hal*_*lil 10

这是错误消息的重要部分。

\n
>= 2.0.0, ~> 3.27, ~> 4.0\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  1. 您请求的版本大于或等于2.0.0
  2. \n
  3. 您更喜欢 3.27 版本
  4. \n
  5. 您更喜欢 4.0 版本
  6. \n
\n

2和3不可能同时出现。

\n

这种特定情况的解决方案是停止同时请求 2 个不同的版本。

\n

检查可用提供程序的版本:

\n
!+?main ~/Projects/x/src/x-devops/terraform/env/test> terraform providers\n\nProviders required by configuration:\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 module.test-sonar\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 provider[registry.terraform.io/hashicorp/aws]\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 module.client_vpn\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 provider[registry.terraform.io/hashicorp/aws]\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 module.test-appserver\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 provider[registry.terraform.io/hashicorp/aws] ~> 3.27\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 module.test-vpn-server\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 provider[registry.terraform.io/hashicorp/aws]\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 module.test-networking\n...\n
Run Code Online (Sandbox Code Playgroud)\n

有一个模块要求3.27.

\n

找到所有请求 3.27 的模块并将其更新为 4.0。

\n

这应该可以解决此类问题。

\n

  • 谢谢你的解释,我面临着同样的错误,这拯救了我的一天 (2认同)