Terraform 报告错误“无法查询可用的提供程序包”

lea*_*ner 7 terraform terraform-provider-azure

我为 Mongodb terraform 模块创建了 main.tf 文件,如下所示。

resource "mongodbatlas_teams" "test" {
  org_id     = null
  name       = "MVPAdmin_Team"
  usernames  = ["user1@email.com", "user2@email.com", "user3@email.com"]
}

resource "mongodbatlas_project" "test" {
  name   = "MVP_Project"
  org_id = null

  teams {
    team_id    = null
    role_names = ["GROUP_CLUSTER_MANAGER"]

  }
  
}
resource "mongodbatlas_project_ip_access_list" "test" {
  project_id = null
  ip_address = null
  comment    = "IP address for MVP Dev cluster testing"
}

resource "mongodbatlas_cluster" "test" {
  name                = "MVP_DevCluster"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  cluster_type        = REPLICASET
  state_name          = var.state_name
  replication specs {
     num_shards= var.num_shards
     region_config {
       region_name = "AU-EA"
       electable_nodes = var.electable_nodes
       priority        = var.priority
       read_only_nodes = var.read_only_nodes
     }  
  }

  provider_backup_enabled = var.provider_backup_enabled
  auto_scaling_disk_gb_enabled = var.auto_scaling_disk_gb_enabled
  mongo_db_major_version = var.mongo_db_major_version
  provider_name = "Azure"
  provider_disk_type_name = var.provider_disk_type_name
  provider_instance_size_name = var.provider_instance_size_name



  mongodbatlas_database_user {
    username = var.username
    password = var.password
    auth_database_name = var.auth_database_name
    role_name = var.role_name
    database_name = var.database_name
  }
  mongodbatlas_database_snapshot_backup_policy {
    policy_item = var.policy_item
    frequency_type = var.frequency_type
    retention_value = var.retention_value
  
 }

 advanced_configuration {
      minimum_enabled_tls_protocol = var.minimum_enabled_tls_protocol
   no_table_scan                  = var.no_table_scan
   connection_string              = var.connection_string

 } 
}
Run Code Online (Sandbox Code Playgroud)

然而,terraform init报告如下:

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/mongodbatlas...

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

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

Run Code Online (Sandbox Code Playgroud)

知道出了什么问题吗?

Mar*_*ins 8

该错误消息解释了看到此错误消息的最可能原因:您已直接从 Terraform v0.12 升级到 Terraform v0.14,而没有运行Terraform v0.13 升级步骤

如果您首先升级到 Terraform v0.13 并按照这些说明进行操作,那么升级工具应该能够在此处提供有关要更改的内容的更具体说明,甚至可能能够自动为您升级您的配置。

但是,如果您愿意,您也可以手动添加 v0.13 升级工具将插入的配置块,以指定您打算mongodb/mongodbatlas在此模块中使用提供程序作为“mongodbatlas”:

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

v0.13 升级指南中还有一些上述内容未解决的其他注意事项,因此,如果您在尝试上面所示的操作后看到不同的错误消息,您可能仍然需要执行该升级指南中描述的步骤。

  • 谢谢您的帮助!只是一个友好的通知:您在 monogdb/mongodbatlas 中有一个拼写错误应该是:source = "mongodb/mongodbatlas" (2认同)