在 "dependsOn" 中使用 ARM 模板函数"reference"失败并显示错误:此位置不应出现模板函数'reference'



我正在使用ARM模板中链接模板的输出进行部署。以下是我的模板:

  1. 链接模板:
"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. 使用此链接模板的模板:
"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'))]"
}
}
]

我指的是通过模板2中的模板1部署的集群名称;dependensOn";但失败,返回错误。第"84"行和第"9"列的模板资源"adx-jtcjiot-dev-sea-adxdb001"无效:在此位置不应使用模板函数"reference"。有人使用过这样的引用函数进行部署吗?我想将集群和数据库部署分开,因为数据库创建可能经常同时发生。我不想在数据库模板中硬编码集群名称。有其他方法可以做到这一点或解决这个错误吗。

提前感谢!

我不确定我是否理解您为什么首先要将它们分开。

简单地把它们放在一起,就像这里的例子一样:https://learn.microsoft.com/en-us/azure/data-explorer/automated-deploy-overview#step-3创建一个模板来部署集群?

最终,dependsOn不接受错误消息中显示的引用函数。我的第二个想法是使用resourceID函数来查找资源名称,但显然这是不受支持的。因此,我在变量中定义了服务器名称,并将其用于数据库";名称字段";

因为您依赖于同一部署中部署的资源,所以不需要定义资源id或使用引用。您只需使用资源部署的名称(如arm模板中所定义(,如下所示:

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

这将确保在Kusto集群部署完成之前不会开始部署数据库。

相关内容

最新更新