簡體   English   中英

在 Azure 和 Terraform 上的 cosmosdb 帳戶中創建 sqldb 的問題

[英]Issue in creating sqldb in cosmosdb account on Azure with Terraform

目標:使用 terraform 在 azure 中創建 cosmosdb 帳戶和 sqldb

我嘗試了什么:

resource "azurerm_cosmosdb_account" "cosmosaccount" {
  name                = "cosmosdb"
  location            = var.location
  resource_group_name = var.rg_name  
  offer_type          = var.cosmosdb_offer_type
  kind                = var.cosmosdb_kind
  is_virtual_network_filter_enabled = "true"
  ip_range_filter     = var.ip_range_filter

  capabilities {
    name = "EnableTable"
  }

  enable_automatic_failover = false

  consistency_policy {
    consistency_level       = var.cosmosdb_consistancy_level
    max_interval_in_seconds = 5
    max_staleness_prefix    = 100
  }

  geo_location {
    location          = var.location
    failover_priority = 0
  }

  virtual_network_rule  {
    id                = var.subnet_id
    ignore_missing_vnet_service_endpoint = true
  }
}


resource "azurerm_cosmosdb_sql_database" "comosdbsqldb" {
  name                = "driving"
  resource_group_name = azurerm_cosmosdb_account.cosmosaccount.resource_group_name
  account_name        = azurerm_cosmosdb_account.cosmosaccount.name
  throughput          = 500  
  depends_on = [azurerm_cosmosdb_account.cosmosaccount]  
}


resource "azurerm_cosmosdb_sql_container" "mdhistcontainer" {
  name                  = "metadata_history"
  resource_group_name   = azurerm_cosmosdb_account.cosmosaccount.resource_group_name
  account_name          = azurerm_cosmosdb_account.cosmosaccount.name
  database_name         = azurerm_cosmosdb_sql_database.comosdbsqldb.name
  partition_key_path    = "/definition/id"
  partition_key_version = 1
  throughput            = 500

  indexing_policy {
    indexing_mode = "consistent"

    included_path {
      path = "/*"
    }

    included_path {
      path = "/included/?"
    }

    excluded_path {
      path = "/excluded/?"
    }
  }

  unique_key {
    paths = ["/definition/idlong", "/definition/idshort"]
  }
  depends_on = [azurerm_cosmosdb_sql_database.comosdbsqldb]
}

我面臨的問題:

  • 它成功創建了 cosmosdb 帳戶,但未能創建 sqldb

我得到的錯誤:

Error: checking for presence of Sql Database: (Name "driving" / Database Account Name "cosmosaccount" / 
Resource Group "xxxxxxxxxxxx"): documentdb.SQLResourcesClient#GetSQLDatabase: 
Failure responding to request: StatusCode=405 -- Original Error: autorest/azure: Service returned an error. 
Status=405 Code="MethodNotAllowed" Message="Requests for API sql are not supported for this account.
\r\nActivityId: 2d79ca83-9534-46e8-a7cf-cef1fd76e752, Microsoft.Azure.Documents.Common/2.14.0"
│ 
│   with module.cosmosdb.azurerm_cosmosdb_sql_database.comosdbsqldb,
│   on ../modules/cosmosdb/main.tf line 46, in resource "azurerm_cosmosdb_sql_database" "comosdbsqldb":
│   46: resource "azurerm_cosmosdb_sql_database" "comosdbsqldb"

我也將DocumentDBContributor角色賦予了服務主體,但仍然出現此錯誤。 我正在關注以下有關語法的文檔。似乎我完全遵循https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cosmosdb_sql_database

請建議如何解決此錯誤。

我相信您收到此錯誤是因為您正在創建一個針對表 API 的 Cosmos DB 帳戶,並嘗試在該帳戶中創建一個具有自定義名稱的數據庫。

  capabilities {
    name = "EnableTable"
  }

使用表 API,您無法創建具有任何名稱的數據庫。 帳戶中只能有一個數據庫,並且其名稱是固定的。 數據庫的名稱應該是TablesDB

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM