-
Notifications
You must be signed in to change notification settings - Fork 338
/
Copy pathcreate.sh
60 lines (51 loc) · 2.05 KB
/
create.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# Passed validation in Cloud Shell on 2/20/2022
# <FullScript>
# Create a SQL API database and container
# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
failoverLocation="South Central US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="create-sql-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
database="msdocs-db-sql-cosmos"
container="container1"
partitionKey="/zipcode"
# Create a resource group
echo "Creating $resourceGroup in $location..."
az group create --name $resourceGroup --location "$location" --tags $tag
# Create a Cosmos account for SQL API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --default-consistency-level Eventual --locations regionName="$location" failoverPriority=0 isZoneRedundant=False --locations regionName="$failoverLocation" failoverPriority=1 isZoneRedundant=False
# Create a SQL API database
echo "Creating $database"
az cosmosdb sql database create --account-name $account --resource-group $resourceGroup --name $database
# Define the index policy for the container, include spatial and composite indexes
printf '
{
"indexingMode": "consistent",
"includedPaths": [
{"path": "/*"}
],
"excludedPaths": [
{ "path": "/headquarters/employees/?"}
],
"spatialIndexes": [
{"path": "/*", "types": ["Point"]}
],
"compositeIndexes":[
[
{ "path":"/name", "order":"ascending" },
{ "path":"/age", "order":"descending" }
]
]
}' > "idxpolicy-$randomIdentifier.json"
# Create a SQL API container
echo "Creating $container with $maxThroughput"
az cosmosdb sql container create --account-name $account --resource-group $resourceGroup --database-name $database --name $container --partition-key-path $partitionKey --throughput 400 --idx @idxpolicy-$randomIdentifier.json
# Clean up temporary index policy file
rm -f "idxpolicy-$randomIdentifier.json"
# </FullScript>
# echo "Deleting all resources"
# az group delete --name $resourceGroup -y