unable to set autoscale in cosmos db using terraform

Viewed 603

I am trying to add autoscale settings to cosmos db but its not allowing the shard_key value as null. because right now we dont have shard_key but still want to utlitze the auto scale feature. I can see in azure portal that is allowed when I import the resources created without shard_key in the portal the value is showing null, but while creation I am not able to do it.

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
  }
 
}
1 Answers

I tested it on my environment ,setting up autoscale setting without shard key is not possible using terraform.

Error:

enter image description here

When I add some value in Shard_key , it gets success.

enter image description here

From Terraform Documentation:

autoscale_settings - (Optional) An autoscale_settings block as defined below. This must be set upon database creation otherwise it cannot be updated without a manual terraform destroy-apply. Requires shard_key to be set.

As per the above its mandatory to set the Shard_key value for adding the autoscale settings using terraform.

For alternate solution , you have to use ARM_template/Bicep/Portal. You can refer the below link for templates on the same.

Reference:

Azure-QuickStart-Templates

Related