首页 > 解决方案 > 如何在 terraform 0.14 中选择正确的 docker 提供程序

问题描述

为了与 Docker 集成,我将 terraform 设置如下:

所需的提供者

 docker = {
      source = "kreuzwerker/docker"
      version = "2.11.0"
    }

该提供者的实例化

provider "docker" {
}

最后我在资源中按如下方式使用它:

data "docker_registry_image" "myapp" {
  name = some_image_url
}

当我运行时terraform init,它似乎仍然指的是 HashiCorp 的“旧” terraform 提供程序:

Initializing modules...

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/random versions matching "3.0.1"...
- Finding hashicorp/null versions matching "~> 3.0.0"...
- Finding hashicorp/external versions matching "~> 2.0.0"...
- Finding kreuzwerker/docker versions matching "2.11.0"...
- Finding latest version of hashicorp/docker...
- Finding hashicorp/google versions matching "~> 3.56.0"...
- Finding hashicorp/azurerm versions matching "~> 2.46.1"...
- Installing hashicorp/null v3.0.0...
- Installed hashicorp/null v3.0.0 (signed by HashiCorp)
- Installing hashicorp/external v2.0.0...
- Installed hashicorp/external v2.0.0 (signed by HashiCorp)
- Installing kreuzwerker/docker v2.11.0...
- Installed kreuzwerker/docker v2.11.0 (self-signed, key ID 24E54F214569A8A5)
- Installing hashicorp/google v3.56.0...
- Installed hashicorp/google v3.56.0 (signed by HashiCorp)
- Installing hashicorp/azurerm v2.46.1...
- Installed hashicorp/azurerm v2.46.1 (signed by HashiCorp)
- Installing hashicorp/random v3.0.1...
- Installed hashicorp/random v3.0.1 (signed by HashiCorp)

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html

Error: Failed to query available provider packages

Could not retrieve the list of available versions for provider
hashicorp/docker: provider registry registry.terraform.io does not have a
provider named registry.terraform.io/hashicorp/docker

If you have just upgraded directly from Terraform v0.12 to Terraform v0.14
then please upgrade to Terraform v0.13 first and follow the upgrade guide for
that release, which might help you address this problem.

Did you intend to use kreuzwerker/docker? If so, you must specify that source
address in each module which requires that provider. To see which modules are
currently depending on hashicorp/docker, run the following command:
    terraform providers

当我运行时,terraform providers我确实看到了参考,原因是docker_registry_image

...
        ├── provider[registry.terraform.io/hashicorp/docker]
...

笔记:

我该如何解决这个问题?谢谢!

标签: dockerterraformterraform-provider-docker

解决方案


看来我们没有正确迁移。

我已经通过将我的恐怖版本设置回0.13并运行来解决它terraform 0.13upgrade。执行命令后,我0.14.6再次升级到并且一切正常。

来源:https ://www.terraform.io/docs/cli/commands/0.13upgrade.html

命令做了什么?

在我的模块文件夹(我使用 docker 资源)中创建了一个文件,其中versions.tf包含以下内容:

terraform {
  required_providers {
    docker = {
      source = "kreuzwerker/docker"
    }
    google = {
      source = "hashicorp/google"
    }
    random = {
      source = "hashicorp/random"
    }
  }
  required_version = ">= 0.13"
}

请注意,此处创建的内容将取决于您的具体情况。

它还在我的工作目录中创建了一个文件,其中包含:

terraform {
  required_version = ">= 0.13"
}

(提供程序位于不同的文件中,并且已经拥有正确的 docker 源,因此仅将所需的版本添加添加到新文件中。)


推荐阅读