我的provider.tf在根目录中有以下内容
terraform {
required_version = ">= 1.0.5"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "= 3.8.0"
}
mongodbatlas = {
source = "mongodb/mongodbatlas"
}
}
}
我在terraform init
阶段中得到以下错误
Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider
│ hashicorp/mongodbatlas: provider registry registry.terraform.io does not
│ have a provider named registry.terraform.io/hashicorp/mongodbatlas
│
│ Did you intend to use mongodb/mongodbatlas? If so, you must specify that
│ source address in each module which requires that provider. To see which
│ modules are currently depending on hashicorp/mongodbatlas, run the
│ following command:
│ terraform providers
在这个错误之后,我在我的mongodb atlas
子模块中也包含了下面的内容,它需要它,并且它起了作用。
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
}
}
}
我的问题是为什么我需要这样做?我不必为任何其他所需的提供商做这件事?提前谢谢。
仅针对出现相同错误的访问者,请按照说明操作
检查消息:
您打算使用mongodb/mongodbatlas吗?如果是,则必须指定每个模块中需要该提供者的源地址。
您需要将MongoDB提供程序放在您使用的每个模块中。
运行terraform providers
并检查哪些模块需要MongoDB。
在每个模块中创建一个版本.tf文件。添加以下代码(使用您想要的版本(:
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas",
version = "1.8.0"
}
}
}
关于需要将required_providers放入每个模块
测试未托管在Terraform注册表上的Atlas Provider版本(即预发布版本(
测试Terraform Atlas的开发/预发布版本未托管在Terraform注册表上的提供程序,您将需要以创建Terraform Provider网络镜像。
提供商网络镜像协议是一种可选协议,您可以可以实现为提供替代安装源Terraform提供者,无论其来源注册。Terraform仅当在CLI中显式激活网络镜像时才使用网络镜像配置的provider_installation块。启用后,网络镜像可以为属于任何注册表主机名的提供程序提供服务可以允许一个组织为他们的所有Terraform提供商提供服务打算从内部服务器使用,而不是从每个服务器提供者的原始注册表。
来源:https://github.com/mongodb/terraform-provider-mongodbatlas
mongodb/mongodbatlas不是hashicorp提供程序。您必须在每个模块中明确定义required_providers,因为这些提供程序不是继承的。
这里回答了类似的问题-Terraform同时使用required_providers和provider阻止
要点-如果你使用的提供者不是Terraform的官方提供者,那么你需要指定Terraform required_providers块,让Terraform知道下载提供者插件的来源。
TERRAFORM官方供应商列表-链接