4

While trying to deploy a CosmosDB instance with 2 collections ("MyCollection1", "MyCollection2") I keep getting the error:

NotFound: Entity with the specified id does not exist in the system

So I keep searching for "resourceId" in my custom ARM template (please see below) but cannot find the erorr cause.

I don't understand, why does not the pipeline at least print the line number for me?

pipeline screenshot

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "accountName": {
            "defaultValue": "my-cosmosdb",
            "type": "String"
        }
    },
    "variables": {
        "resourceName": "[concat(resourceGroup().name, '-', parameters('accountName'))]",
        "resourceId": "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]",
        "apiVersion": "[providers('Microsoft.DocumentDB', 'databaseAccounts').apiVersions[0]]"
    },
    "outputs": {
        "CosmosDbConnectionString": {
            "type": "string",
            "value": "[concat('AccountEndpoint=https://', variables('resourceName'), '.documents.azure.com:443/;AccountKey=', listKeys(variables('resourceId'), variables('apiVersion')).primaryMasterKey, ';')]"
        },
        "DatabaseName": {
            "type": "string",
            "value": "MyDB"
        },
        "CollectionName1": {
            "type": "string",
            "value": "MyCollection1"
        },
        "CollectionName2": {
            "type": "string",
            "value": "MyCollection2"
        }
    },
    "resources": [
        {
            "type": "Microsoft.DocumentDB/databaseAccounts",
            "apiVersion": "2020-03-01",
            "name": "[variables('resourceName')]",
            "location": "[resourceGroup().location]",
            "tags": {
                "defaultExperience": "DocumentDB"
            },
            "kind": "GlobalDocumentDB",
            "properties": {
                "publicNetworkAccess": "Enabled",
                "enableAutomaticFailover": false,
                "enableMultipleWriteLocations": false,
                "isVirtualNetworkFilterEnabled": false,
                "virtualNetworkRules": [],
                "disableKeyBasedMetadataWriteAccess": false,
                "databaseAccountOfferType": "Standard",
                "consistencyPolicy": {
                    "defaultConsistencyLevel": "Session",
                    "maxIntervalInSeconds": 5,
                    "maxStalenessPrefix": 100
                },
                "locations": [
                    {
                        "locationName": "[resourceGroup().location]",
                        "provisioningState": "Succeeded",
                        "failoverPriority": 0,
                        "isZoneRedundant": false
                    }
                ],
                "capabilities": []
            }
        },
        {
            "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases",
            "apiVersion": "2020-03-01",
            "name": "[concat(variables('resourceName'), '/MyDB')]",
            "dependsOn": [
                "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
            ],
            "properties": {
                "resource": {
                    "id": "MyDB"
                },
                "options": {}
            }
        },
        {
            "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers",
            "apiVersion": "2020-03-01",
            "name": "[concat(variables('resourceName'), '/MyDB/MyCollection1')]",
            "dependsOn": [
                "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('resourceName'), 'MyDB')]",
                "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
            ],
            "properties": {
                "resource": {
                    "id": "MyCollection1",
                    "indexingPolicy": {
                        "indexingMode": "consistent",
                        "automatic": true,
                        "includedPaths": [
                            {
                                "path": "/*"
                            }
                        ],
                        "excludedPaths": [
                            {
                                "path": "/\"_etag\"/?"
                            }
                        ]
                    },
                    "partitionKey": {
                        "paths": [
                            "/partitionKey"
                        ],
                        "kind": "Hash"
                    },
                    "uniqueKeyPolicy": {
                        "uniqueKeys": []
                    },
                    "conflictResolutionPolicy": {
                        "mode": "LastWriterWins",
                        "conflictResolutionPath": "/_ts"
                    }
                },
                "options": {}
            }
        },
        {
            "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers",
            "apiVersion": "2020-03-01",
            "name": "[concat(variables('resourceName'), '/MyDB/MyCollection2')]",
            "dependsOn": [
                "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('resourceName'), 'MyDB')]",
                "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
            ],
            "properties": {
                "resource": {
                    "id": "MyCollection2",
                    "indexingPolicy": {
                        "indexingMode": "consistent",
                        "automatic": true,
                        "includedPaths": [
                            {
                                "path": "/*"
                            }
                        ],
                        "excludedPaths": [
                            {
                                "path": "/\"_etag\"/?"
                            }
                        ]
                    },
                    "partitionKey": {
                        "paths": [
                            "/partitionKey"
                        ],
                        "kind": "Hash"
                    },
                    "uniqueKeyPolicy": {
                        "uniqueKeys": []
                    },
                    "conflictResolutionPolicy": {
                        "mode": "LastWriterWins",
                        "conflictResolutionPath": "/_ts"
                    }
                },
                "options": {}
            }
        },
        {
            "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/throughputSettings",
            "apiVersion": "2020-03-01",
            "name": "[concat(variables('resourceName'), '/MyDB/default')]",
            "dependsOn": [
                "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('resourceName'), 'MyDB')]",
                "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
            ],
            "properties": {
                "resource": {
                    "throughput": 400
                }
            }
        }
    ]
}

UPDATE:

I have removed the part creating collections and the error is still there.

UPDATE 2:

The following part seemingly causes the error, but why?

{
    "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/throughputSettings",
    "apiVersion": "2020-03-01",
    "name": "[concat(variables('resourceName'), '/MyDB/default')]",
    "dependsOn": [
        "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('resourceName'), 'MyDB')]",
        "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
    ],
    "properties": {
        "resource": {
            "throughput": 400
        }
    }
}

What is wrong with the dependsOn entry "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('resourceName'), 'MyDB')]?

UPDATE 3:

Trying to deploy the complete ARM template listed above manually results in:

screenshot throughput error

screenshot error

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
  • 1
    this doesnt look like it, tbh. arm templates dont throw errors like this (unless this was modified really recently) when depends on is wrong – 4c74356b41 May 09 '20 at 15:23
  • Yes, I have tried editing my ARM template, after referring to [List of Access Keys from Output](https://devkimchi.com/2018/01/05/list-of-access-keys-from-output-values-after-arm-template-deployment/) because I need the endpoint in my output – Alexander Farber May 09 '20 at 17:02

2 Answers2

8

Try setting your throughput in the options for your database.

UPDATE: You cannot specify throughput on a resource that did not have it when initially provisioned. Databases and containers provisioned without throughput cannot be updated later to have it. Conversely, a resource provisioned with throughput, cannot be updated to remove. You must delete and recreate the resource. This will require migrating your data.

{
        "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases",
        "apiVersion": "2020-03-01",
        "name": "[concat(variables('resourceName'), '/MyDB')]",
        "dependsOn": [
            "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
        ],
        "properties": {
            "resource": {
                "id": "MyDB"
            },
            "options": { "throughput": "[parameters('throughput')]" }
        }
    },

btw, there are lots of samples you can use to start with here Cosmos DB templates

Mark Brown
  • 8,113
  • 2
  • 17
  • 21
  • 1
    Unfortunately, this approach does not work: `BadRequest: Throughput update is not supported for resources created without dedicated throughput` – Alexander Farber May 10 '20 at 10:01
  • Should I use `Microsoft.DocumentDB/databaseAccounts/sqlDatabases/throughputSettings` or maybe [Microsoft.DocumentDB/databaseAccounts/tables/throughputSettings](https://learn.microsoft.com/bs-latn-ba/rest/api/cosmos-db-resource-provider/tableresources/gettablethroughput)? – Alexander Farber May 10 '20 at 12:41
  • Or is it `Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/throughputSettings`? I am so confused :-/ – Alexander Farber May 10 '20 at 12:53
  • 6
    You cannot update throughput on a resource which did not have it set at creation time. When creating a resource set it's throughput in options as shown. When you want to update throughput redeploy the same template with a new throughput value. Thanks. – Mark Brown May 10 '20 at 21:17
  • 2
    As per @MarkBrown comment I had this same problem, and it was because I used the same initial script as you - which created database, but failed to add throughput in seperate step. Once I delete the database the code above worked. – tank104 Oct 21 '21 at 00:29
0

The following has worked for me, I had to replace "sqlDatabases/throughputSettings" by "sqlDatabases/containers/throughputSettings":

{
    "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/throughputSettings",
    "apiVersion": "2020-03-01",
    "name": "[concat(variables('resourceName'), '/', variables('DatabaseName'), '/', variables('CollectionName1'), '/default')]",
    "dependsOn": [
        "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers', variables('resourceName'), variables('databaseName'), variables('CollectionName1'))]",
        "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('resourceName'), variables('databaseName'))]",
        "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
    ],
    "properties": {
        "resource": {
            "throughput": 400
        }
    }
}

And then similar entry for CollectionName2

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416