Azure -使用Terraform还原CosmosDB帐户

rjee0c15  于 2022-11-30  发布在  其他
关注(0)|答案(2)|浏览(148)

我正在尝试使用Terraform帐户创建新的Azure CosmosDB帐户:

创建模式=“恢复”

基本上,我尝试从现有的数据库恢复,代码需要源数据库的另一个输入属性:

“源cosmosdb帐户ID”=“/订阅/33 f91226-e87 e-4cdf 67 a1 dae 4 e/提供程序/Microsoft.文档数据库/位置/westeu/可恢复数据库帐户/测试源数据库名称”

我遵循的是文档所指示的格式:

示例为/订阅/{订阅ID}/提供程序/Microsoft.DocumentDB/位置/{位置}/可恢复数据库帐户/{可恢复数据库帐户名称}

然而,当我应用代码时,我得到以下错误:
代码=“BadRequest”消息=“无法解析URI /订阅/33 f91226-e87 e-4ca 1dae 4 e/提供程序/Microsoft.DocumentDB/位置/westeu/可恢复数据库帐户/测试源数据库名称
这个问题似乎是我在源代码ID中写入位置的方式,但是我找不到任何相关的信息来说明正确的方式。
如果有人在terraform中成功地做到了这一点,我将非常感谢source_cosmosdb_account_id的示例。
谢谢
使用的配置:

backup = [
    {
      type                = "Continuous"
      interval_in_minutes = null
      retention_in_hours  = null
      storage_redundancy  = null
    }
  ]
  restore   = [
    {
      "source_cosmosdb_account_id" = "/subscriptions/33f6-e87e-4cdf-9480-7b1dae/providers/Microsoft.DocumentDB/locations/westeu/restorableDatabaseAccounts/test-source-db-name"
      "restore_timestamp_in_utc" = "2022-11-18T14:00:00.00Z"
      "database" = []
    }
  ]
zlwx9yxi

zlwx9yxi1#

我最近遇到了同样的问题,发现terraform文档已经过时了。
您需要具有create_mode =“恢复”
备份应按如下方式配置

backup = [
    {
      type                = "Continuous"
      interval_in_minutes = 0
      retention_in_hours  = 0
      storage_redundancy  = "Geo"
    }
  ]

格式/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/restorableDatabaseAccounts/{restorableDatabaseAccountName}不正确
尝试使用/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/restorableDatabaseAccounts/{**instanceId**}
您可以在json视图

中找到cosmosinstanceId

5ktev3wc

5ktev3wc2#

我尝试在我的环境中重现该问题。我得到了相同的错误,Failed to parse uri /subscriptions/xxxx/providers/Microsoft.DocumentDB/locations/westeu/restorableDatabaseAccounts/test-source-db-name
与:

resource "azurerm_cosmosdb_account" "db" {
  name                = "tfex-cosmos-db-31960"
  location            = "westus2"
  resource_group_name = data.azurerm_resource_group.example.name
  offer_type          = "Standard"
  kind                = "MongoDB"
 create_mode         =  "Restore"
 

restore {    source_cosmosdb_account_id=data.azurerm_cosmosdb_restorable_database_accounts.example.id
  source_cosmosdb_account_id="/subscriptions/xxxxx/providers/Microsoft.DocumentDB/locations/westeurope/restorableDatabaseAccounts/tfex-cosmos-db-31960?api-version=2022-05-15"
  restore_timestamp_in_utc="2022-11-25T22:06:00Z"
  
}
   

...
}

如果我尝试用westeu作为你给的位置,在我的情况下,我得到以下错误,因为它必须是westeurope作为支持的azure。

也请检查
来自cosmosdb_account的注解|terraform注册表:“连续”类型的数据库帐户(或在过去30天内删除的帐户)是可还原的帐户,不能对可还原的数据库帐户执行创建/更新/删除操作。***They can only be read and be retrieved by azurerm_cosmosdb_restorable_database_accounts.***

  • 与restore-account-continuous-backup一样,azure portal , powershell,Azure CLI , ARM template支持恢复cosmos db帐户|微软学习

使用azurerm提供程序,我只能通过连续备份类型阅读以下内容:

resource "azurerm_cosmosdb_account" "db" {
  name                = "tfex-cosmos-db-31960"
  location            = "westus2"
  resource_group_name = data.azurerm_resource_group.example.name
  offer_type          = "Standard"
  kind                = "MongoDB"
 

  enable_automatic_failover = true
  

  capabilities {
    name = "EnableAggregationPipeline"
  }

  capabilities {
    name = "mongoEnableDocLevelTTL"
  }

  capabilities {
    name = "MongoDBv3.4"
  }

  capabilities {
    name = "EnableMongo"
  }

  consistency_policy {
    consistency_level       = "BoundedStaleness"
    max_interval_in_seconds = 300
    max_staleness_prefix    = 100000
  }

  geo_location {
    location          = "eastus"
    failover_priority = 0
  }


backup{

type = "Continuous"
//interval_in_minutes=60

}

data "azurerm_cosmosdb_restorable_database_accounts" "example" {
  name     = azurerm_cosmosdb_account.db.name
  location = "West Europe"
}

output "name" {
  value=data.azurerm_cosmosdb_restorable_database_accounts.example.name
  
}
output "id" {
  value = data.azurerm_cosmosdb_restorable_database_accounts.example.id
}

输出:

尝试使用azapi_resource block in terraform进行相同的检查:
因为它需要参数,如API版本、必须来自Cosmosdb_restorable_database_accounts列表的源帐户ID,并且必须形成与API资源兼容的URI,如https://management.azure.com/subscriptions/subid/providers/Microsoft.DocumentDB/locations/West US/restorableDatabaseAccounts/d9b2xxx10d?api-version=2022-05-15

相关问题