如何使用Terraform创建Azure CosmosDB Serverless?

huangapple go评论59阅读模式
英文:

How can I create an Azure CosmosDB Serverless using Terraform?

问题

我一直在尝试使用Terraform创建无服务器的Azure Cosmos DB数据库,但一直无法成功。

在阅读了Microsoft的文档和Azurerm Terraform注册表文档后,我能够编写以下资源:

resource "azurerm_cosmosdb_account" "resume-challenge-cosmosdb" {
  name                      = var.cosmosdb-name
  location                  = var.region
  resource_group_name       = azurerm_resource_group.cloud-resume-rg.name
  offer_type                = "Standard"
  kind                      = "GlobalDocumentDB"
  enable_automatic_failover = false
  enable_free_tier          = true
  consistency_policy {
    consistency_level       = "BoundedStaleness"
    max_interval_in_seconds = 300
    max_staleness_prefix    = 100000
  }
  geo_location {
    location          = "brazilsouth"
    failover_priority = 0
  }
}

但它创建的是普通版本的Cosmos DB。

英文:

I've been trying to create the serverless offer of the cosmosdb database using Terraform, but haven't been able to do so.

After reading Microsoft's documentations and the Azurerm terraform registry documentations, I could code this resource:

resource "azurerm_cosmosdb_account" "resume-challenge-cosmosdb" {
name                      = var.cosmosdb-name
  location                  = var.region
  resource_group_name       = azurerm_resource_group.cloud-resume-rg.name
  offer_type                = "Standard"
  kind                      = "GlobalDocumentDB"
  enable_automatic_failover = false
  enable_free_tier          = true
  consistency_policy {
    consistency_level       = "BoundedStaleness"
    max_interval_in_seconds = 300
    max_staleness_prefix    = 100000
  }
  geo_location {
    location          = "brazilsouth"
    failover_priority = 0
  }
}

but it creates the regular version of the cosmosdb.

答案1

得分: 1

要使 CosmosDB 帐户在使用 AzureRM Terraform 提供程序时变成无服务器模式,您需要在 azurerm_cosmosdb_account 上启用 EnableServerless 功能。为此,您必须添加一个 capabilities 块,并设置 name = "EnableServerless"。将此应用于您上面的示例如下所示:

resource "azurerm_cosmosdb_account" "resume-challenge-cosmosdb" {
  name                      = var.cosmosdb-name
  location                  = var.region
  resource_group_name       = azurerm_resource_group.cloud-resume-rg.name
  offer_type                = "Standard"
  kind                      = "GlobalDocumentDB"
  enable_automatic_failover = false
  enable_free_tier          = true
  consistency_policy {
    consistency_level       = "BoundedStaleness"
    max_interval_in_seconds = 300
    max_staleness_prefix    = 100000
  }
  geo_location {
    location          = "brazilsouth"
    failover_priority = 0
  }
  capabilities {
    name = "EnableServerless"
  }
}

我是根据在 azurerm_cosmosdb_account 资源文档上搜索 "serverless" 这个词来找到这个信息的。

英文:

To make a CosmosDB account serverless using the AzureRM Terraform provider you need to enable the EnableServerless capability on the azurerm_cosmosdb_account. To do this you must add a capabilities block with name = "EnableServerless". Applying this to your above example would look like so:

resource "azurerm_cosmosdb_account" "resume-challenge-cosmosdb" {
name                      = var.cosmosdb-name
  location                  = var.region
  resource_group_name       = azurerm_resource_group.cloud-resume-rg.name
  offer_type                = "Standard"
  kind                      = "GlobalDocumentDB"
  enable_automatic_failover = false
  enable_free_tier          = true
  consistency_policy {
    consistency_level       = "BoundedStaleness"
    max_interval_in_seconds = 300
    max_staleness_prefix    = 100000
  }
  geo_location {
    location          = "brazilsouth"
    failover_priority = 0
  }
  capabilities {
    name = "EnableServerless"
  }
}

I found this by searching for the word "serverless" on the azurerm_cosmosdb_account resource docs.

huangapple
  • 本文由 发表于 2023年2月19日 02:32:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75495510.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定