1
votes

I'm trying to conditionally provide resource property values through translation of runtime resource properties within a copyIndex loop..

Upon deploying the following ARM template, I receive the error:

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'. 'The template resource '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm-name}' is not found.' (Code: 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. If I hard-code the Extension Type, there are no errors and the Extension is installed on the VM with the same ID.

Unfortunately, I don't know if this is a bug within ARM or if I'm just doing something wrong..

{
    "$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:

[
    { "name": "vm-name", "location": "azure-region" }
]
1
change Microsoft.Compute to Microsoft.ClassicComputeLily_user4045
these are not v1 resourcesJoeBrockhaus

1 Answers

0
votes

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. 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

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.

I will do some more poking and see if we can't nail this down.