[英]ARM Error: The Template Resource is not found using resource(), copyIndex()
I'm trying to conditionally provide resource property values through translation of runtime resource properties within a copyIndex loop.. 我试图通过在copyIndex循环中转换运行时资源属性来有条件地提供资源属性值。
Upon deploying the following ARM template, I receive the error: 部署以下ARM模板后,我收到错误:
Unable to process template language expressions for resource '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm-name}/extensions/Microsoft.EnterpriseCloud.Monitoring' at line '30' and column '10'.
无法处理资源'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm-name}/extensions/Microsoft.EnterpriseCloud.Monitoring'在第30行的模板语言表达式列'10'。 'The template resource '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm-name}' is not found.'
找不到'模板资源'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm-name}'。 (Code: InvalidTemplate)
(代码:InvalidTemplate)
"type": "[variables('extensionType')[reference(concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachines')[copyIndex()].name)).storageProfile.osDisk.osType]]",
However, the VM exists with the ID it provides, so it doesn't make sense that the engine cannot find it. 但是,VM存在其提供的ID,因此引擎无法找到它是没有意义的。 If I hard-code the Extension Type, there are no errors and the Extension is installed on the VM with the same ID.
如果我对扩展类型进行硬编码,则没有错误,并且具有相同ID的VM上安装了扩展。
Unfortunately, I don't know if this is a bug within ARM or if I'm just doing something wrong.. 不幸的是,我不知道这是ARM中的一个错误,还是我只是做错了什么..
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceResourceId": { "type": "string" },
"virtualMachines": { "type": "array" }
},
"variables": {
"extensionType": {
"Windows": "MicrosoftMonitoringAgent",
"Linux": "OmsAgentForLinux"
}
},
"resources": [
{
"copy": {
"name": "VMMonitoringExtensionsCopy",
"count": "[length(parameters('virtualMachines'))]"
},
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2015-05-01-preview",
"location": "[parameters('virtualMachines')[copyIndex()].location]",
"name": "[concat(parameters('virtualMachines')[copyIndex()].name, '/Microsoft.EnterpriseCloud.Monitoring')]",
"properties": {
"publisher": "Microsoft.EnterpriseCloud.Monitoring",
"type": "[variables('extensionType')[reference(concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachines')[copyIndex()].name)).storageProfile.osDisk.osType]]",
"typeHandlerVersion": "1.0",
"autoUpgradeMinorVersion": true,
"settings": {
"workspaceId": "[reference(parameters('workspaceResourceId'), '2015-11-01-preview').customerId]"
},
"protectedSettings": {
"workspaceKey": "[listKeys(parameters('workspaceResourceId'), '2015-11-01-preview').primarySharedKey]"
}
}
}
]
}
The object array being passed in for virtualMachines looks like this: 为virtualMachines传入的对象数组如下所示:
[
{ "name": "vm-name", "location": "azure-region" }
]
A couple things you can try: 您可以尝试几件事:
1) Assuming the VM is not defined in the same template try using the "full" resourceId in the reference function. 1)假设未在同一模板中定义VM,请尝试在引用函数中使用“full”resourceId。 See the last example in this doc: https://azure.microsoft.com/en-us/documentation/articles/resource-group-template-functions/#reference - it seems like the error already knows the full resourceId, but it's worth trying
请参阅此文档中的最后一个示例: https : //azure.microsoft.com/en-us/documentation/articles/resource-group-template-functions/#reference - 似乎错误已经知道完整的resourceId,但它是值得尝试
2) the other thought is that the reference function is evaluated at runtime and the resource provider doesn't like the expression but that's a swag. 2)另一个想法是在运行时评估引用函数,资源提供者不喜欢表达式,但这是一个赃物。
I will do some more poking and see if we can't nail this down. 我会做一些更多的戳,看看我们是否能解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.