您打算使用 mongodb/mongodbatlas 吗?如果是这样,您必须指定?每个模块中需要该提供者的源地址

Abd*_*lah 7 terraform mongodb-atlas

我的根目录中的provider.tf中有以下内容

\n
terraform {\n  required_version = ">= 1.0.5"\n  required_providers {\n    azurerm = {\n      source  = "hashicorp/azurerm"\n      version = "= 3.8.0"\n    }\n    mongodbatlas = {\n      source = "mongodb/mongodbatlas"\n    }\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

terraform init我在阶段中遇到以下错误

\n
Error: Failed to query available provider packages\n\xe2\x94\x82 \n\xe2\x94\x82 Could not retrieve the list of available versions for provider\n\xe2\x94\x82 hashicorp/mongodbatlas: provider registry registry.terraform.io does not\n\xe2\x94\x82 have a provider named registry.terraform.io/hashicorp/mongodbatlas\n\xe2\x94\x82 \n\xe2\x94\x82 Did you intend to use mongodb/mongodbatlas? If so, you must specify that\n\xe2\x94\x82 source address in each module which requires that provider. To see which\n\xe2\x94\x82 modules are currently depending on hashicorp/mongodbatlas, run the\n\xe2\x94\x82 following command:\n\xe2\x94\x82     terraform providers\n
Run Code Online (Sandbox Code Playgroud)\n

发生此错误后,我也将其包含在我的mongodb atlas子模块中,该模块需要它并且它有效。

\n
terraform {\n  required_providers {\n    mongodbatlas = {\n      source = "mongodb/mongodbatlas"\n    }\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我的问题是为什么我需要这样做?我不需要为任何其他所需的提供商执行此操作吗?提前致谢。

\n

Gui*_* IA 7

对于遇到相同错误的访问者,请按照说明进行操作

检查消息:

您打算使用 mongodb/mongodbatlas 吗?如果是这样,您必须在需要该提供程序的每个模块中指定源地址。

您需要将 MongoDB 提供程序放入您正在使用的每个模块中。

运行terraform providers并检查哪些模块需要 MongoDB。

在每个模块内创建一个versions.tf文件。添加以下代码(使用您想要的版本):

terraform {
  required_providers {
    mongodbatlas = {
      source  = "mongodb/mongodbatlas",
      version = "1.8.0"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

关于需要将required_providers放入每个模块中

测试未托管在 Terraform 注册表上的 Atlas Provider 版本(即预发布版本)

要测试未托管在 Terraform 注册表上的 Terraform Atlas Provider 的开发/预发布版本,您将需要创建 Terraform Provider 网络镜像。

提供程序网络镜像协议是一个可选协议,您可以实现它来为 Terraform 提供程序提供替代安装源,无论其原始注册表如何。仅当您在 CLI 配置的provider_installation 块中显式激活网络镜像时,Terraform 才会使用网络镜像。启用后,网络镜像可以为属于任何注册表主机名的提供程序提供服务,这可以允许组织从内部服务器而不是从每个提供程序的原始注册表来为他们打算使用的所有 Terraform 提供程序提供服务。

来源: https: //github.com/mongodb/terraform-provider-mongodbatlas


Sha*_*Suf 0

类似的问题在这里得到了回答 - Terraform using both required_providers and provider block

要点 - 如果您使用的提供程序不是 Terraform 的官方提供程序之一,那么您需要指定 terraform required_providers 块,让 terraform 知道下载提供程序插件的源。

按 T​​ERRAFORM 划分的官方提供商列表 -链接