【问题标题】:How to select correct docker provider in terraform 0.14如何在 terraform 0.14 中选择正确的 docker 提供程序
【发布时间】:2021-05-13 00:01:21
【问题描述】:

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

所需的提供者

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

该提供者的实例化

provider "docker" {
}

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

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

注意事项:

  • 所有其他供应商都使用最新版本。
  • 我使用的是 terraform 0.14.6。
  • 上面给出的资源是我正在使用的唯一的 docker 资源
  • 我已经尝试在提供者和资源上使用别名,但它不起作用。

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

【问题讨论】:

  • 我在 terraform 云中遇到了同样的问题。我认为是 docker 提供程序语法的问题。找到解决办法后我会在这里回复。
  • @AndreLeonRangel 我已经为我们的案例解决了这个问题!我已经发布了答案;希望它也适合你! ;)
  • 我必须在 hashcorp 的社区中创建支持票和主题。检查详细信息。感谢您的回答。 discuss.hashicorp.com/t/…

标签: docker terraform terraform-provider-docker


【解决方案1】:

我们好像没有正确迁移。

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

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

命令做了什么?

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

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 源,因此只将所需的版本添加到新文件中。)

【讨论】:

  • 我需要 2 个来源“hashicorp/google”和“hashicorp/random”吗?
  • 不,这些都不需要 :) 我怀疑你主要使用 docker?
猜你喜欢
  • 1970-01-01
  • 2020-05-16
  • 1970-01-01
  • 2021-11-17
  • 2021-04-14
  • 2021-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多