self service approach for creating AzureCosmos DB collection and indexes using AzureBicepse or ARM template

53 views Asked by At

We were having Terraform IaC to create cosmos DB database, along with collections and index inside each collection Right now, as per Developers requirement, the infra person is executing this terraform plan and apply.

As the number of such creation of DBs or collection and indexes are getting increased, decided to make the DB, collection and index creation as a self service, where developers can input the hierarchy in their applications source code repo , eg: <env>-cosmos.yaml, and azure devops pipeline along with Biceps or ARM template can fetch this values and apply to the given cosmos DB in an automated way. Here we are trying to have the <env>-cosmos.yaml as below, where the databasenames are given as items and collections and indexes are mapped as dictionaries inside them.

- mongodatabasename: mydb-1
  autoscaling_enabled: true
  max_throughput: 1000
  mydb-collection-1: {
    create_collection: true
    name             : "mydb-collection-1",
    database_name    : "mydb-2",
    shard_key        : "_id",
    analytical_storage_ttl: 0,
    default_ttl_seconds: xxxx
    mydb-collection-1_additional_indexes: [
               {
                 keys = ["xxxxxx",]
                 unique = false
               },
               {
                 keys = ["yyyyy",] 
                 unique = false
               },
               {
                 keys = ["zzzzz",] 
                 unique = false
               } ]  
  }  
  mydb-collection-2 = {
    create_collection: true
    name          : "mydb-collection-2"
    database_name : "mydb-3"
    shard_key     : "_id"
    default_ttl_seconds : -1
    mydb-collection-2_additional_indexes: [
               {
                 keys = ["xxxxxx",]
                 unique = false
               },
               {
                 keys = ["yyyyy",] 
                 unique = false
               },
               {
                 keys = ["zzzzz",] 
                 unique = false
               } ]      
  }
 
  
  
- mongodatabasename: mydb-2
  autoscaling_enabled: true
  max_throughput: 1000 
  mydb2-collection-1: {
    create_collection: true
    name             : "mydb-collection-1",
    database_name    : "mydb-2",
    shard_key        : "_id",
    analytical_storage_ttl: 0,
    default_ttl_seconds: xxxx
    mydb2-collection-1_additional_indexes: [
               {
                 keys = ["xxxxxx",]
                 unique = false
               },
               {
                 keys = ["yyyyy",] 
                 unique = false
               },
               {
                 keys = ["zzzzz",] 
                 unique = false
               } ]  
  }  
  mydb2-collection-2 = {
    create_collection: true
    name          : "mydb-collection-2"
    database_name : "mydb-3"
    shard_key     : "_id"
    default_ttl_seconds : -1
    mydb-collection-_additional_indexes: [
               {
                 keys = ["xxxxxx",]
                 unique = false
               },
               {
                 keys = ["yyyyy",] 
                 unique = false
               },
               {
                 keys = ["zzzzz",] 
                 unique = false
               } ]      
  }
0

There are 0 answers