01 Run account list command (Windows/macOS/Linux) with custom output filters to list the IDs of the cloud subscriptions available in your Azure cloud account:
az account list
--query '[*].id'
02 The command output should return the requested subscription identifiers (IDs):
[
"abcdabcd-1234-abcd-1234-abcdabcdabcd",
"abcd1234-abcd-1234-abcd-abcd1234abcd"
]
03 Run account set command (Windows/macOS/Linux) with the ID of the Azure cloud subscription that you want to examine as the identifier parameter to set the selected subscription to be the current active subscription (the command does not produce an output):
az account set
--subscription abcdabcd-1234-abcd-1234-abcdabcdabcd
04 Run cosmosdb list command (Windows/macOS/Linux) with custom query filters to list the name and the associated resource group for each Azure Cosmos DB account available in the selected subscription:
az cosmosdb list
--output table
--query '[*].{name:name, resourceGroup:resourceGroup}'
05 The command output should return the requested Cosmos DB account names:
Name ResourceGroup
--------------------------- ------------------------------
cc-project5-cosmos-database cloud-shell-storage-westeurope
cc-cosmos-prod-dba-account cloud-shell-storage-westeurope
06 Run cosmosdb show command (Windows/macOS/Linux) with the name of the Azure Cosmos DB account that you want to examine as the identifier parameter and custom output filters to describe the ID of the selected Cosmos DB account:
az cosmosdb show
--resource-group cloud-shell-storage-westeurope
--account-name cc-project5-cosmos-database
--query 'id'
07 The command output should return the full ID for your Cosmos DB account:
"/subscriptions/abcdabcd-1234-abcd-1234-abcdabcdabcd/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.DocumentDB/databaseAccounts/cc-project5-cosmos-database"
08 Microsoft Azure Cosmos DB uses two built-in roles: Cosmos DB Built-in Data Reader and Cosmos DB Built-in Data Contributor. The Cosmos DB Built-in Data Reader role contains actions for reading metadata on Cosmos DB accounts, reading items in a container, executing queries, and reading the change feed. To create an SQL role assignment for the Cosmos DB Built-in Data Reader role under your Azure Cosmos DB account, run cosmosdb sql role assignment create command (OSX/Linux/UNIX). For --role-definition-name, specify the name of the required built-in role (i.e., Cosmos DB Built-in Data Contributor). For --principal-id, specify the ID of the identity that needs access to manage data in your Azure Cosmos DB account. For --scope, specify the full ID of the Cosmos DB account, identified in step 7:
az cosmosdb sql role assignment create
--resource-group cloud-shell-storage-westeurope
--account-name cc-project5-cosmos-database
--role-definition-name "Cosmos DB Built-in Data Contributor"
--principal-id "abcd1234-abcd-1234-abcd-abcd1234abcd"
--scope "/subscriptions/abcdabcd-1234-abcd-1234-abcdabcdabcd/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.DocumentDB/databaseAccounts/cc-project5-cosmos-database"
09 The command output should return the information available for the newly created role assignment:
{
"id": "/subscriptions/abcdabcd-1234-abcd-1234-abcdabcdabcd/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.DocumentDB/databaseAccounts/cc-project5-cosmos-database/sqlRoleAssignments/c21cc3d9-be45-4426-9622-c448b3db752c",
"name": "c21cc3d9-be45-4426-9622-c448b3db752c",
"principalId": "abcd1234-abcd-1234-abcd-abcd1234abcd",
"resourceGroup": "cloud-shell-storage-westeurope",
"roleDefinitionId": "/subscriptions/abcdabcd-1234-abcd-1234-abcdabcdabcd/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.DocumentDB/databaseAccounts/cc-project5-cosmos-database/sqlRoleDefinitions/00000000-0000-0000-0000-000000000002",
"scope": "/subscriptions/abcdabcd-1234-abcd-1234-abcdabcdabcd/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.DocumentDB/databaseAccounts/cc-project5-cosmos-database",
"type": "Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments"
}
10 The Cosmos DB Built-in Data Contributor role contains actions for reading metadata on Cosmos DB accounts, reading and writing with containers, and reading and writing with items. To create an SQL role assignment for the Cosmos DB Built-in Data Contributor role under your Azure Cosmos DB account, run cosmosdb sql role assignment create command (OSX/Linux/UNIX), as shown in the example listed below:
az cosmosdb sql role assignment create
--resource-group cloud-shell-storage-westeurope
--account-name cc-project5-cosmos-database
--role-definition-name "Cosmos DB Built-in Data Reader"
--principal-id "abcd1234-abcd-1234-abcd-abcd1234abcd"
--scope "/subscriptions/abcdabcd-1234-abcd-1234-abcdabcdabcd/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.DocumentDB/databaseAccounts/cc-project5-cosmos-database"
11 The command output should return the information available for the new role assignment:
{
"id": "/subscriptions/abcdabcd-1234-abcd-1234-abcdabcdabcd/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.DocumentDB/databaseAccounts/cc-project5-cosmos-database/sqlRoleAssignments/35b36284-edf1-4c8d-a2a5-f5002eeb4ae7",
"name": "35b36284-edf1-4c8d-a2a5-f5002eeb4ae7",
"principalId": "abcd1234-abcd-1234-abcd-abcd1234abcd",
"resourceGroup": "cloud-shell-storage-westeurope",
"roleDefinitionId": "/subscriptions/abcdabcd-1234-abcd-1234-abcdabcdabcd/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.DocumentDB/databaseAccounts/cc-project5-cosmos-database/sqlRoleDefinitions/00000000-0000-0000-0000-000000000001",
"scope": "/subscriptions/abcdabcd-1234-abcd-1234-abcdabcdabcd/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.DocumentDB/databaseAccounts/cc-project5-cosmos-database",
"type": "Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments"
}
12 Repeat steps no. 6 - 11 for each Azure Cosmos DB account that you want to configure, available in the selected subscription.
13 Repeat steps no. 3 – 12 for each Azure subscription created in your Microsoft Azure cloud account.