如何 select 更正 docker terraform 0.14 中的提供程序

How to select correct docker provider in terraform 0.14

为了与 Docker 集成,我按如下方式设置了我的地形:

所需的供应商

 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]
...

备注:

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

看来我们没有正确迁移。

我已经通过将我的恐怖版本设置回 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"
}

Note that what is created here will depend on your specific situation.

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

terraform {
  required_version = ">= 0.13"
}

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