Is it possible to create a CosmosDB with ARM templates? - azure

I'm trying to create an ARM template that provisions a CosmosDB instance, the only documentation I've found however is for DocumentDB which I'm aware is what Cosmos used to be called. If I provision a DocumentDB cluster will that create a CosmosDB instance? If not Does anybody have any experience of provisioning a CosmosDB with an ARM template and if so, is there any reference material I can read?

Yeah, those are the same. Just use this examples repo. You are looking for any examples with documentdb or cosmosdb in the name.
Alternatively you can créate a CosmosDB instance in the portal and look at the template that is being used to créate it (under deployments in the resource group where you deployed it).

Related

Automatically adding data to cosmos DB through ARM template

I made an ARM template which runs through an azure devops pipeline to create a new cosmos instance and put two collections inside it. I'd like to put some data inside the collections (fixed values, same every time). Everything is created in the standard way, e.g. the collections are using
"type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers"
I think these are the relevant docs.
I haven't found mentions of automatically adding data much, but it's such an obviously useful thing I'm sure it will have been added. If I need to add another step to my pipeline to add data, that's an option too.
ARM templates are not able to insert data into Cosmos DB or any service with a data plane for many of the reasons listed in the comments and more.
If you need to both provision a Cosmos resource and then insert data into it you may want to consider creating another ARM template to deploy an Azure Data Factory resource and then invoke the pipeline using PowerShell to copy the data from Blob Storage into the Cosmos DB collection. Based upon the ARM doc you referenced above it sounds as though you are creating a MongoDB collection resource. ADF supports MongoDB so this should work very well.
You can find the ADF ARM template docs here and the ADF PowerShell docs can be found here. If you're new to using ARM to create ADF resources, I recommend first creating it using the Azure Portal, then export it and examine the properties you will need to drive with parameters or variables during deployment.
PS: I'm not sure why but this container resource path (below) you pointed to in your question should not used as it breaks a few things in ARM, namely, you cannot put a resource lock on it or use Azure Policy. Please use the latest api-version which as of this writing is 2021-04-15.
"type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers"

Use ARM template to create directories in Azure Storage Containers?

I can't seem to find documentation saying this can be done? But neither saying that this can't be done. So wondering if anyone else has had this idea/query in past.
I have ARM template to generate our new data lake and it's creating storage account and container. It'd have been great to create folder structure also using the template. Or maybe the directories don't count as a 'resource'?
ARM api does not support that: https://learn.microsoft.com/en-us/rest/api/storagerp/blobcontainers/create
you can only work on containers\file shares\tables and queues. You cannot create object inside those. So its not possible with ARM Templates. They can only operate against ARM apis.
you can use deploymentScript resource as a workaround

Azure CosmosDB: Can One Set RBAC per Database/Collection

Given an Azure CosmosDB DB instance that is created from the Azure portal, it is possible to create multiple databases from a shell connection with the following commands:
use someNewDbName;
db.someNewCollectionName.insert({});
With other DB providers that expose MongoDB APIs, it is possible to configure user roles on either a database or colletion level (for users that exist on the same DB instance).
For example, with self-hosted MongoDB, the db.createUser() allows the roles parameter which accepts the db option. MongoDB Atlas allows similar operations to be performed through their UI.
Is it possible to do the same with CosmosDB? Within the Azure Portal, selecting the CosmosDB, and then Access control (IAM) and then Roles leads to a list of built in roles as well as a text that says it is possible to define your own roles but no indication as to how to do that.
I am able to create custom role with following method using Powershell
This role was displayed in the list of available role under "Add Role assignment" Tab
These links might help you
https://learn.microsoft.com/en-us/azure/role-based-access-control/tutorial-custom-role-powershell
https://learn.microsoft.com/en-us/azure/role-based-access-control/custom-roles
I also tried to create users and roles for an Azure CosmosDB using the MongoDB interface and followed this documentation: https://learn.microsoft.com/en-GB/azure/cosmos-db/secure-access-to-data?tabs=using-primary-key.
It seems however that this is simply not supported by the MongoDB interface. I followed the above documentation using the role-based access control approach and eventually run into the following issue when executing the below command:
az cosmosdb sql role definition create --account-name <some-account> --resource-group <some-resource-group> --body #role-definition.json
(BadRequest) The Database Account [<some-database>] has API type
[MongoDB] which is invalid for processing SQL Role Definitions.
The above is also confirmed documentation on the (resource)token-based approach: https://learn.microsoft.com/en-us/rest/api/cosmos-db/permissions (see first line):
Azure Cosmos DB is a globally distributed multi-model database that supports the document, graph, and key-value data models. The content in this section is for managing permission resources using the SQL API via REST.
Hope that this helps.

How to configure a Cosmos Db collection during deployment

When deploying a Cosmos Db database in GlobalDocumentDB mode using the Azure resource manager template there is no way to configure collections in the database during deployment that I can tell.
During a ARM template deployment is there any way to either (in order of preference)
Configure the collections in a Cosmos Db database directly in a way that I have overlooked.
Do a series of REST requests from within the template to configure the db.
Do a single REST request within the template to hit a Azure Function with a HttpTrigger that will configure the database.
You should be able to use these Templates.
Containers:
https://learn.microsoft.com/en-us/azure/templates/microsoft.documentdb/2015-04-08/databaseaccounts/apis/databases/containers
Collections:
https://learn.microsoft.com/en-us/azure/templates/microsoft.documentdb/2015-04-08/databaseaccounts/apis/databases/collections
All Microsoft.DocumentDB Resource Types:
https://learn.microsoft.com/en-us/azure/templates/microsoft.documentdb/allversions
These pages were published on 05/01/2019 & are for API version 2015-04-08.
ARM templates is used to create Azure resources, there is no way to configure collection during deploy ARM template. To configure collections, I suggest you use REST API. Before creating a collection, we need to create a database first. Following are documents which show us how to create DocumentDB databases and collections.
Create Database
Create Collection

Azure Resource Manager SQL db templates

I am trying to create an ARM templates for Azure SQL DB deployment. I started by exporting template for an existing Azure sql database which was created and configured from portal. However I see quite a few fields which look a bit unfamiliar to me on usage - examples provided below:
a. kind
b. serviceLevelObjective
c. currentServiceObjectiveId
d. requestedServiceObjectiveId
e. containmentState
f. readScale
Is there any place where I can find information on what each of these properties/keys means and what are the valid values against these so that I know how to use these?
Your best bet is Azure Rest API Reference it has got examples and definitions for parameters.
Also, you don't need all of those, you can just use a "regular" way of creating Azure SQL stuff defined here.
Also, MSDN reference: https://msdn.microsoft.com/en-us/library/azure/mt163685.aspx

Resources