0

I am using output from a linked template in my ARM template for deployment below are my templates :

  1. Link template :
"resources": [
        {
            "name": "[variables('clusterName')]",
            "type": "Microsoft.Kusto/clusters",
            "sku": {
                "name": "Standard_D13_v2",
                "tier": "Standard",
                "capacity": 2
            },
            "apiVersion": "2020-09-18",
            "location": "[parameters('location')]",
            "properties": {
                "trustedExternalTenants": [],
                "optimizedAutoscale": {
                    "version": 1,
                    "isEnabled": true,
                    "minimum": 2,
                    "maximum": 10
                },
                "enableDiskEncryption": false,
                "enableStreamingIngest": true,
                "enablePurge": false,
                "enableDoubleEncryption": false,
                "engineType": "V3"
            }
        }
    ],
    "outputs": {
    "clusterNameResult": {
      "type": "string",
      "value": "[variables('clusterName')]"
    }
  }
  1. Template using this linked template:
"resources": [
        {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2021-04-01",
            "name": "linkedTemplate",
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                "uri": "[concat(uri(deployment().properties.templateLink.uri, 'Dataexplorer_Deployment_Template.json'))]",
                "contentVersion": "1.0.0.0"
                }
            },
            "copy": {
                "name": "databasecopy",
                "count": "[length(parameters('databaseNameList'))]"
              }
        },
        {
            "type": "Microsoft.Kusto/Clusters/Databases",
            "apiVersion": "2020-09-18",
            "name": "[variables('databaseNameList').databaseNames[copyIndex()]]",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Kusto/Clusters',  reference('linkedTemplate').outputs['clusterNameResult'].value)]"
            ],
            "kind": "ReadWrite",
            "properties": {
                "softDeletePeriod": "P5D",
                "hotCachePeriod": "P1D"
            },
            "copy": {
                "name": "databasecopy",
                "count": "[length(parameters('databaseNameList'))]"
              }
        },
        {
            "type": "Microsoft.Kusto/Clusters/Databases/PrincipalAssignments",
            "apiVersion": "2020-09-18",
            "name": "[variables('databaseNameList').databaseNames[copyIndex()]]",
            "dependsOn": [
                "[resourceId('Microsoft.Kusto/Clusters/Databases', variables('databaseNameList').databaseNames[copyIndex()])]",
                "[resourceId('Microsoft.Kusto/Clusters', reference('linkedTemplate').outputs['clusterNameResult'].value)]"
            ],
            "properties": {
                "principalId": "abc.def@gmail.com",
                "role": "Viewer",
                "principalType": "User",
                "tenantId": "523547f7-9d12-45c5-9g15-2ysb44a3r2m4"
            },
            "copy": {
                "name": "databasecopy",
                "count": "[length(parameters('databaseNameList'))]"
              }
        }

    ]

I am refering to the cluster name deployed through template 1 in template 2 , specified at "dependsOn" but it fails with error The template resource 'adx-jtcjiot-dev-sea-adxdb001' at line '84' and column '9' is not valid: The template function 'reference' is not expected at this location. Has anyone used reference functions for deployment like this, I want to keep cluster and database deployment separately as database creation might occur often at the same time i don't want to hardcode the clustername in the database template. Is there any other way to do it or to resolve this error.

Thanks in advance!

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
newbee123
  • 21
  • 1
  • 2
  • Hi newbee123; this discussion of the different ways you can define dependencies might help you understand your options here: https://stackoverflow.com/questions/42685192/azure-arm-templates-dependson – Vince Bowdren Feb 05 '22 at 16:07

3 Answers3

1

I'm not sure I understand why you want to keep those separate in the first place.

What about simply putting them together as in the example here: https://learn.microsoft.com/en-us/azure/data-explorer/automated-deploy-overview#step-3-create-an-arm-template-to-deploy-the-cluster?

  • 1
    I had done it previously in one arm template, but my intention was to decouple the database deployment from server deployment as new databases might needed to be created even after server creation. – newbee123 Feb 05 '22 at 17:29
0

Because you're depending on a resource being deployed in the same deployment, you don't need to define a resource id, or use a reference. You can just use the name of the resource deployment (as defined in the arm template), like this:

{
    "type": "Microsoft.Resources/deployments",
    "name": "linkedTemplate",
    etc
},
{
    "type": "Microsoft.Kusto/Clusters/Databases",
    etc
    "dependsOn": [
        "linkedTemplate"
    ]
}

That will ensure that the deployment of the database will not start until the deployment of the Kusto cluster has been completed.

Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
  • This will make your ARM template syntactically valid, and should work in practice; but I think you would probably be better off following the advice given by Vincent-Philippe Lauzon in his answer, and defining the database as a child deployment of the cluster deployment. – Vince Bowdren Feb 05 '22 at 14:55
  • eventually dependsOn doesn't accept reference functions as appeared in the error message. My second thought was to find out resource name using resourceID function but apparently that's not supported . so I have defined the server name in variables and using it for database "name field" – newbee123 Feb 05 '22 at 17:32
0

Ultimately, dependsOn doesn't accept reference functions as appeared in the error message. My second thought was to find out resource name using resourceID function, but apparently that's not supported. So, instead I have defined the server name in variables and used it for database "name field"

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
newbee123
  • 21
  • 1
  • 2