是否可以在 ARM 模板中创建 documentDB 数据库和帐户
Is it possible to create a documentDB database and account in a ARM template
在 Azure 门户中,可以在创建流分析作业输出的步骤中创建 documentDB 数据库和集合。是否可以在使用 ARM 模板创建流作业和输出时执行相同的操作?
我发现只能使用 ARM 模板将 documentDB 帐户创建为资源,但是否可以在设置作业输出时创建数据库和集合,就像在门户中一样?
根据我的经验,目前不支持在ARM模板中创建documentDB数据库和集合。我会与 Azure 团队确认。如果有任何反馈我会post在这里。
我的 work-around 是我们可以使用 REST API 来做到这一点。如果存在 documentDB 数据库和集合,那么我们可以通过 ARM 模板使用 documentDb 数据库和集合创建作业的输出。
{
"$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]"
}
}
}
}
]
}
万一有人偶然发现:现在可以通过 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://docs.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
}
]
}
]
}
}
}
}
]
}
在 Azure 门户中,可以在创建流分析作业输出的步骤中创建 documentDB 数据库和集合。是否可以在使用 ARM 模板创建流作业和输出时执行相同的操作?
我发现只能使用 ARM 模板将 documentDB 帐户创建为资源,但是否可以在设置作业输出时创建数据库和集合,就像在门户中一样?
根据我的经验,目前不支持在ARM模板中创建documentDB数据库和集合。我会与 Azure 团队确认。如果有任何反馈我会post在这里。
我的 work-around 是我们可以使用 REST API 来做到这一点。如果存在 documentDB 数据库和集合,那么我们可以通过 ARM 模板使用 documentDb 数据库和集合创建作业的输出。
{
"$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]"
}
}
}
}
]
}
万一有人偶然发现:现在可以通过 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://docs.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
}
]
}
]
}
}
}
}
]
}