Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_cosmosdb_mongo_collection sharded indexing not working #8868

Closed
animeshajain04 opened this issue Oct 13, 2020 · 2 comments
Closed

azurerm_cosmosdb_mongo_collection sharded indexing not working #8868

animeshajain04 opened this issue Oct 13, 2020 · 2 comments

Comments

@animeshajain04
Copy link

animeshajain04 commented Oct 13, 2020

I am trying to create a new mongo sharded collection in cosmos account with terraform with following configurations:

resource "azurerm_cosmosdb_mongo_collection" "chunks" {
  name                = "chunks"
  resource_group_name = module.resource-group-content-service.name
  account_name        = module.sierra-cosmosdb-content-service.name
  database_name       = azurerm_cosmosdb_mongo_database.content-service.name

  throughput          = 4000
  default_ttl_seconds = 864000

  index {
    keys   = ["n"]
    unique = false
  }
  index {
    keys   = ["files_id","n"]
    unique = true
  }
  shard_key = "files_id"

  lifecycle {
    ignore_changes = [throughput]
  }
}

Following are the cosmosDB account main conf

  kind                              = "MongoDB"
  capabilities                      = ["mongoEnableDocLevelTTL","EnableMongo"]

Following is the terraform and arm configuration:

provider "azurerm" {
  version = "=2.29.0"
  features {}

  subscription_id = "*****"
}

terraform {
  required_version = "= 0.12.7"
}

The respective ARM template section which works is:

      {
            "type": "Microsoft.DocumentDB/databaseAccounts/mongodbDatabases/collections",
            "apiVersion": "2020-06-01-preview",
            "name": "[concat(parameters('databaseAccounts_cjm_authoring_dev_name'), '/', parameters('databaseAccounts_cjm_authoring_dev_name'), '/publishedContent.chunks')]",
            "dependsOn": [
                "[resourceId('Microsoft.DocumentDB/databaseAccounts/mongodbDatabases', parameters('databaseAccounts_cjm_authoring_dev_name'), parameters('databaseAccounts_cjm_authoring_dev_name'))]",
                "[resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('databaseAccounts_cjm_authoring_dev_name'))]"
            ],
            "properties": {
                "resource": {
                    "id": "publishedContent.chunks",
                    "shardKey": {
                        "files_id": "Hash"
                    },
                    "indexes": [
                        {
                            "key": {
                                "keys": [
                                    "_id"
                                ]
                            }
                        },
                        {
                            "key": {
                                "keys": [
                                    "n"
                                ]
                            }
                        },
                        {
                            "key": {
                                "keys": [
                                    "files_id",
                                    "n"
                                ]
                            },
                            "options": {
                                "unique": true
                            }
                        }
                    ]
                },
                "options": {}
            }
        },

ARM works however, terraform configuration fails with error as

Code="BadRequest" Message="cannot create unique index over { n : 1.0, files_id : 1.0 } with shard key pattern { files_id : 1.0 }\r\nActivityId: d0827ed2-cb8b-4098-8506-9a92c0801c56, Microsoft.Azure.Documents.Common/2.11.0, Microsoft.Azure.Documents.Common/2.11.0, Microsoft.Azure.Documents.Common/2.11.0, Microsoft.Azure.Documents.Common/2.11.0"
@animeshajain04
Copy link
Author

#8602

pulling this in resolved the issue.

@ghost
Copy link

ghost commented Nov 12, 2020

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!

@ghost ghost locked as resolved and limited conversation to collaborators Nov 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant