Terraform-provider-azurerm: Support for Cosmos DB serverless

Created on 19 Aug 2020  ยท  9Comments  ยท  Source: terraform-providers/terraform-provider-azurerm

Community Note

  • Please vote on this issue by adding a ๐Ÿ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Add support for the new serverless version of Cosmos DB. This appears to be enabled by adding EnableServerless to the capabilities property.

New or Affected Resource(s)

  • azurerm_cosmosdb_account

Potential Terraform Configuration

resource "azurerm_cosmosdb_account" "db" {
  name                = "my-cosmos-db"
  location            = "${azurerm_resource_group.rg.location}"
  resource_group_name = "${azurerm_resource_group.rg.name}"
  offer_type          = "Standard"
  kind                    = "GlobalDocumentDB"

  enable_automatic_failover = false
  capabilities        = [{
    name = "EnableServerless"
  }]
}

References

  • https://devblogs.microsoft.com/cosmosdb/serverless-preview/

  • enhancement preview serviccosmosdb

    Most helpful comment

    Re-opening since there's some more to do here

    All 9 comments

    I was actually thinking it might be useful as as a different offer_type.

    offer_type = "Serverless"
    

    @cwoolum That is not how it currently works in the Azure API, so I don't think that's a good idea. It could cause problems in the future.

    I think supporting this would require changes to resources other than azurerm_cosmosdb_account. Provisioning an account in serverless mode will alter the behaviour of more than just the account. See the Cosmos DB Serverless documentation.
    https://docs.microsoft.com/en-us/azure/cosmos-db/serverless#using-serverless-resources

    Specifically, this part:

    Provisioning throughput is not required on serverless containers, so the following statements are applicable:

    • You can't pass any throughput when creating a serverless container and doing so returns an error.
    • You can't read or update the throughput on a serverless container and doing so returns an error.
    • You can't create a shared throughput database in a serverless account and doing so returns an error.

    I tried to create a azurerm_cosmosdb_sql_database and azurerm_cosmosdb_sql_container on a Serverless Cosmos DB account that I provisioned using an ARM template. Terraform failed to create these resources because it was making calls that are rejected on a Serverless Cosmos DB account.

    Closing since this appears to have been fixed by #8553 which shipped as a part of 2.29 yesterday - thanks for the heads up @ricohomewood :)

    Actually it does not work. When you run terraform second time with 2.29 you get this error:

    Error: Error reading Throughput on Cosmos SQL Database "xxx" (Account: "xxx") ID: documentdb.SQLResourcesClient#GetSQLDatabaseThroughput: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="Message: {\"code\":\"BadRequest\",\"message\":\"Reading or replacing offers is not supported for serverless accounts.\r\nActivityId: xxx, Microsoft.Azure.Documents.Common/2.11.0\"}, Request URI: /offers, RequestStats: , SDK: Microsoft.Azure.Documents.Common/2.11.0"

    That is what I was talking about in my earlier comment in this issue. It's not as simple as supporting an additional attribute value. Certain calls to the CosmosDB resources are blocked in Serverless mode because they are no longer relevant.

    @tombuildsstuff I really think that this issue needs to be re-opened, because the provider currently doesn't _really_ support Serverless mode. Just passing the capability flag is not enough.

    Re-opening since there's some more to do here

    Supporting serverless would introduce really big benefit for our project. and would be excited to see this is fixed soon ๐Ÿ‘

    I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

    If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error ๐Ÿค– ๐Ÿ™‰ , please reach out to my human friends ๐Ÿ‘‰ [email protected]. Thanks!

    Was this page helpful?
    0 / 5 - 0 ratings