Reputation: 157
In the Azure portal it is possible to create a documentDB database and collection in the step where you create the output of a Stream Analytics Job. Is it possible to do the same while creating the stream job and output with a ARM template?
I have found that it is only possible to create a documentDB account as a resource with an ARM template, but is it possible to create the database and collection while setting the output of the job, as it is in the portal?
Upvotes: 1
Views: 1594
Reputation: 18546
In case anybody stumbles across this: It is now possible to create databases and containers via ARM.
ARM support for databases, containers, and other resources in Azure Resource Manager
Azure Cosmos DB now provides support for Databases, Containers and Offers in Azure Resource Manager. Users can now provision databases and containers, and set throughput using Azure Resource Manager templates or PowerShell. This support is available across all APIs including SQL (Core), MongoDB, Cassandra, Gremlin, and Table. This capability also allows customers to create custom RBAC roles to create, delete, or modify the settings on databases and containers in Azure Cosmos DB. To learn more and to get started, see Azure Cosmos DB Azure Resource Manager templates.
https://learn.microsoft.com/en-us/azure/cosmos-db/manage-sql-with-resource-manager
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"accountName": {
"type": "string",
"defaultValue": "[concat('sql-', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Cosmos DB account name"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for the Cosmos DB account."
}
},
"primaryRegion":{
"type":"string",
"metadata": {
"description": "The primary replica region for the Cosmos DB account."
}
},
"secondaryRegion":{
"type":"string",
"metadata": {
"description": "The secondary replica region for the Cosmos DB account."
}
},
"defaultConsistencyLevel": {
"type": "string",
"defaultValue": "Session",
"allowedValues": [ "Eventual", "ConsistentPrefix", "Session", "BoundedStaleness", "Strong" ],
"metadata": {
"description": "The default consistency level of the Cosmos DB account."
}
},
"maxStalenessPrefix": {
"type": "int",
"minValue": 10,
"defaultValue": 100000,
"maxValue": 2147483647,
"metadata": {
"description": "Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 1000000. Multi Region: 100000 to 1000000."
}
},
"maxIntervalInSeconds": {
"type": "int",
"minValue": 5,
"defaultValue": 300,
"maxValue": 86400,
"metadata": {
"description": "Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400."
}
},
"multipleWriteLocations": {
"type": "bool",
"defaultValue": true,
"allowedValues": [ true, false ],
"metadata": {
"description": "Enable multi-master to make all regions writable."
}
},
"automaticFailover": {
"type": "bool",
"defaultValue": false,
"allowedValues": [ true, false ],
"metadata": {
"description": "Enable automatic failover for regions. Ignored when Multi-Master is enabled"
}
},
"databaseName": {
"type": "string",
"metadata": {
"description": "The name for the SQL database"
}
},
"throughput": {
"type": "int",
"defaultValue": 400,
"minValue": 400,
"maxValue": 1000000,
"metadata": {
"description": "The throughput for the database"
}
},
"container1Name": {
"type": "string",
"defaultValue": "container1",
"metadata": {
"description": "The name for the first SQL container"
}
},
"container2Name": {
"type": "string",
"defaultValue": "container2",
"metadata": {
"description": "The name for the second SQL container"
}
}
},
"variables": {
"accountName": "[toLower(parameters('accountName'))]",
"consistencyPolicy": {
"Eventual": {
"defaultConsistencyLevel": "Eventual"
},
"ConsistentPrefix": {
"defaultConsistencyLevel": "ConsistentPrefix"
},
"Session": {
"defaultConsistencyLevel": "Session"
},
"BoundedStaleness": {
"defaultConsistencyLevel": "BoundedStaleness",
"maxStalenessPrefix": "[parameters('maxStalenessPrefix')]",
"maxIntervalInSeconds": "[parameters('maxIntervalInSeconds')]"
},
"Strong": {
"defaultConsistencyLevel": "Strong"
}
},
"locations":
[
{
"locationName": "[parameters('primaryRegion')]",
"failoverPriority": 0
},
{
"locationName": "[parameters('secondaryRegion')]",
"failoverPriority": 1
}
]
},
"resources":
[
{
"type": "Microsoft.DocumentDB/databaseAccounts",
"name": "[variables('accountName')]",
"apiVersion": "2016-03-31",
"location": "[parameters('location')]",
"kind": "GlobalDocumentDB",
"properties": {
"consistencyPolicy": "[variables('consistencyPolicy')[parameters('defaultConsistencyLevel')]]",
"locations": "[variables('locations')]",
"databaseAccountOfferType": "Standard",
"enableAutomaticFailover": "[parameters('automaticFailover')]",
"enableMultipleWriteLocations": "[parameters('multipleWriteLocations')]"
}
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/apis/databases",
"name": "[concat(variables('accountName'), '/sql/', parameters('databaseName'))]",
"apiVersion": "2016-03-31",
"dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/', variables('accountName'))]" ],
"properties":{
"resource":{
"id": "[parameters('databaseName')]"
},
"options": { "throughput": "[parameters('throughput')]" }
}
},
{
"type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers",
"name": "[concat(variables('accountName'), '/sql/', parameters('databaseName'), '/', parameters('container1Name'))]",
"apiVersion": "2016-03-31",
"dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('accountName'), 'sql', parameters('databaseName'))]" ],
"properties":
{
"resource":{
"id": "[parameters('container1Name')]",
"partitionKey": {
"paths": [
"/MyPartitionKey1"
],
"kind": "Hash"
},
"indexingPolicy": {
"indexingMode": "consistent",
"includedPaths": [{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "number",
"precision": -1
},
{
"kind": "Range",
"dataType": "string",
"precision": -1
}
]
}
],
"excludedPaths": [{
"path": "/MyPathToNotIndex/*"
}
]
}
}
}
},
{
"type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers",
"name": "[concat(variables('accountName'), '/sql/', parameters('databaseName'), '/', parameters('container2Name'))]",
"apiVersion": "2016-03-31",
"dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('accountName'), 'sql', parameters('databaseName'))]" ],
"properties":
{
"resource":{
"id": "[parameters('container2Name')]",
"partitionKey": {
"paths": [
"/MyPartitionKey2"
],
"kind": "Hash"
},
"indexingPolicy": {
"indexingMode": "consistent",
"includedPaths": [{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "number",
"precision": -1
},
{
"kind": "Range",
"dataType": "string",
"precision": -1
}
]
}
]
}
}
}
}
]
}
Upvotes: 2
Reputation: 24549
Base on my experience, it is not supported to create documentDB database and collection in an ARM template currently. I will comfirm it with Azure team. If there is any feedback I will post here.
my work-around is that we could use REST API to do that. If the documentDB database and collection is existed then we could create the output of job with documentDb database and collection via ARM template.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.1.0.0",
"parameters": {
"databaseAccountName": {
"type": "string",
"metadata": {
"description": "The DocumentDB database account name."
}
},
"dbname": {
"type": "string",
"metadata": {
"description": "The database name"
}
},
"collectionname": {
"type": "string",
"metadata": {
"description": "collectionname"
}
},
"streamAnalyticsJobName": {
"type": "string",
"minLength": 3,
"maxLength": 63,
"metadata": {
"description": "Stream Analytics Job Name, can contain alphanumeric characters and hypen and must be 3-63 characters long"
}
},
"numberOfStreamingUnits": {
"type": "int",
"minValue": 1,
"maxValue": 48,
"allowedValues": [
1,
3,
6,
12,
18,
24,
30,
36,
42,
48
],
"metadata": {
"description": "Number of Streaming Units"
}
}
},
"variables": {
"offerType": "Standard"
},
"resources": [
{
"type": "Microsoft.StreamAnalytics/StreamingJobs",
"apiVersion": "2016-03-01",
"name": "[parameters('streamAnalyticsJobName')]",
"location": "[resourceGroup().location]",
"properties": {
"sku": {
"name": "Standard"
},
"outputErrorPolicy": "stop",
"eventsOutOfOrderPolicy": "adjust",
"eventsOutOfOrderMaxDelayInSeconds": 0,
"eventsLateArrivalMaxDelayInSeconds": 5,
"dataLocale": "en-US",
"inputs": [],
"Outputs": [
{
"Name": "relateddb",
"Properties": {
"DataSource": {
"Properties": {
"AccountId": "[parameters('databaseAccountName')]",
"AccountKey": "[listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('databaseAccountName')), '2015-11-06').primaryMasterKey]",
"CollectionNamePattern": "[parameters('collectionname')]",
"Database": "[parameters('dbname')]",
"DocumentId": null,
"PartitionKey": null
},
"Type": "Microsoft.Storage/DocumentDB"
},
"Diagnostics": null,
"Etag": null,
"Serialization": null
}
}
],
"transformation": {
"name": "Transformation",
"properties": {
"streamingUnits": "[parameters('numberOfStreamingUnits')]",
"query": "SELECT\r\n *\r\nINTO\r\n [YourOutputAlias]\r\nFROM\r\n [YourInputAlias]"
}
}
}
}
]
}
Upvotes: 2