首页 > 解决方案 > 无法使用 terraform 在 cosmos db 中设置自动缩放

问题描述

我正在尝试将自动缩放设置添加到 cosmos db,但它不允许 shard_key 值为 null。因为现在我们没有 shard_key 但仍想使用自动缩放功能。我可以在 azure 门户中看到,当我在门户中导入没有 shard_key 创建的资源时,该值显示为空,但在创建时我无法做到这一点。

resource "azurerm_cosmosdb_mongo_collection" "collections" {

  name                = "dbCollName"
  resource_group_name = azurerm_cosmosdb_account.cosmosdb.resource_group_name
  account_name        = local.account_name
  database_name       = "dbName"
  shard_key           = null

  autoscale_settings = {
          max_throughput = 4000
  }
 
}

标签: azureazure-cosmosdbterraform-provider-azure

解决方案


我在我的环境中对其进行了测试,使用 terraform 无法设置没有分片键的自动缩放设置。

错误:

在此处输入图像描述

当我在 Shard_key 中添加一些值时,它会成功。

在此处输入图像描述

来自 Terraform 文档:

autoscale_settings - (可选)如下定义的 autoscale_settings 块。这必须在创建数据库时设置,否则在没有手动 terraform destroy-apply 的情况下无法更新。需要设置 shard_key。

根据上述内容,必须设置 Shard_key 值以使用 terraform 添加自动缩放设置。

对于替代解决方案,您必须使用 ARM_template/Bicep/Portal。您可以参考以下链接以获取相同的模板。

参考:

Azure 快速入门模板


推荐阅读