microsoft / vscode-azurearmtools

Azure Resource Manager Tools for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=msazurermtools.azurerm-vscode-tools
MIT License
135 stars 81 forks source link

Using 'copy' in nested template variables triggered an template validation error #730

Closed yeswps closed 4 years ago

yeswps commented 4 years ago

Currently using azurerm-vscode-tools-0.10.1-alpha.20200520.vsix

Following template validation error is triggered: Template validation failed: Internal error: Validation threw an exception: The template function 'copyIndex' is not expected at this location. The function can only be used in a resource with copy specified. Please see https://aka.ms/arm-copy for usage details.

ARM template below can be successfully deployed without error:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "The location where the resources will be deployed."
            }
        },
        "vaultName": {
            "type": "string",
            "metadata": {
                "description": "The name of the keyvault that contains the secret."
            }
        },
        "secretName": {
            "type": "string",
            "metadata": {
                "description": "The name of the secret in key vault, this secret will be admin user password."
            }
        },
        "vaultResourceGroupName": {
            "type": "string",
            "defaultValue": "[resourceGroup().name]",
            "metadata": {
                "description": "The name of the resource group that contains the keyvault."
            }
        },
        "vaultSubscription": {
            "type": "string",
            "defaultValue": "[subscription().subscriptionId]",
            "metadata": {
                "description": "The name of the subscription that contains the keyvault."
            }
        },
        "adminUsername": {
            "type": "string",
            "metadata": {
                "description": "admin user name"
            }
        },
        "virtualNetworksName": {
            "type": "string",
            "metadata": {
                "description": "virtual network name"
            }
        },
        "subnetName": {
            "type": "string",
            "metadata": {
                "description": "subnet name"
            }
        },
        "storageAccountsName": {
            "type": "string",
            "metadata": {
                "description": "Provide storage account name for diagnostic logging"
            }
        },
        "galleriesExternalId": {
            "type": "string",
            "metadata": {
                "description": "Provide resource id of shared image gallery"
            }
        },
        "galleryImageDefinitionName": {
            "type": "string",
            "metadata": {
                "description": "Provide image defination name in shared image gallery"
            }
        },
        "virtualMachinesName": {
            "type": "string",
            "metadata": {
                "description": "Provide virtual machine name"
            }
        },
        "virtualMachinesSize": {
            "type": "string",
            "defaultValue": "Standard_B2s",
            "metadata": {
                "description": "Provide virtual machine size"
            }
        },
        "vmCount": {
            "type": "int",
            "defaultValue": 1,
            "metadata": {
                "description": "Number of VMs to be deployed"
            }
        },
        "dataDiskArray": {
            "metadata": {
                "diskSizeGB": "Disk size in GB",
                "storageAccountType": "Possible values include: 'Standard_LRS', 'Premium_LRS', 'StandardSSD_LRS', 'UltraSSD_LRS'",
                "caching": "Possible values include: 'ReadWrite','ReadOnly','None' By default, disk caching is 'ReadWrite' for the OS disk and 'None' for data disks. ",
                "exampleArray": [
                    {
                        "diskSizeGB": 4,
                        "storageAccountType": "Standard_LRS",
                        "caching": "None"
                    },
                    {
                        "diskSizeGB": 8,
                        "storageAccountType": "Premium_LRS",
                        "caching": "ReadWrite"
                    }
                ]
            },
            "type": "array",
            "defaultValue": [
            ]
        }
    },
    "variables": {
    },
    "resources": [
        {
            "name": "[if(greater(parameters('vmCount'),1),concat(parameters('virtualMachinesName'),copyIndex('vmCopy',1)),parameters('virtualMachinesName'))]",
            "copy": {
                "name": "vmCopy",
                "count": "[parameters('vmCount')]"
            },
            "apiVersion": "2019-10-01",
            "type": "Microsoft.Resources/deployments",
            "properties": {
                "expressionEvaluationOptions": {
                    "scope": "inner"
                },
                "mode": "Incremental",
                "parameters": {
                    "location": {
                        "value": "[parameters('location')]"
                    },
                    "adminUsername": {
                        "value": "[parameters('adminUsername')]"
                    },
                    "adminPassword": {
                        "reference": {
                            "keyVault": {
                                "id": "[resourceId(parameters('vaultSubscription'), parameters('vaultResourceGroupName'), 'Microsoft.KeyVault/vaults', parameters('vaultName'))]"
                            },
                            "secretName": "[parameters('secretName')]"
                        }
                    },
                    "virtualNetworksName": {
                        "value": "[parameters('virtualNetworksName')]"
                    },
                    "subnetName": {
                        "value": "[parameters('subnetName')]"
                    },
                    "storageAccountsName": {
                        "value": "[parameters('storageAccountsName')]"
                    },
                    "galleriesExternalId": {
                        "value": "[parameters('galleriesExternalId')]"
                    },
                    "galleryImageDefinitionName": {
                        "value": "[parameters('galleryImageDefinitionName')]"
                    },
                    "virtualMachinesName": {
                        "value": "[if(greater(parameters('vmCount'),1),concat(parameters('virtualMachinesName'),copyIndex('vmCopy',1)),parameters('virtualMachinesName'))]"
                    },
                    "virtualMachinesSize": {
                        "value": "[parameters('virtualMachinesSize')]"
                    },
                    "dataDiskArray": {
                        "value": "[parameters('dataDiskArray')]"
                    }
                },
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "location": {
                            "type": "string"
                        },
                        "virtualNetworksName": {
                            "type": "String"
                        },
                        "subnetName": {
                            "type": "string"
                        },
                        "storageAccountsName": {
                            "type": "String"
                        },
                        "galleriesExternalId": {
                            "type": "String"
                        },
                        "galleryImageDefinitionName": {
                            "type": "string"
                        },
                        "adminUsername": {
                            "type": "string"
                        },
                        "adminPassword": {
                            "type": "securestring"
                        },
                        "virtualMachinesName": {
                            "type": "String"
                        },
                        "virtualMachinesSize": {
                            "type": "string"
                        },
                        "dataDiskArray": {
                            "type": "array"
                        }

                    },
                    "variables": {
                        "subnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), parameters('subnetName'))]",
                        "imageId": "[concat(parameters('galleriesExternalId'), '/images/',parameters('galleryImageDefinitionName'))]",
                        "copy": [
                            {
                                "name": "dataDisks",
                                "count": "[if(equals(length(parameters('dataDiskArray')),0),1, length(parameters('dataDiskArray')))]",
                                "input": {
                                    "name": "[concat(parameters('virtualMachinesName'),'_DataDisk',copyIndex('dataDisks',1))]",
                                    "lun": "[if(equals(length(parameters('dataDiskArray')),0),0, copyIndex('dataDisks'))]",
                                    "createOption": "Empty",
                                    "diskSizeGB": "[if(equals(length(parameters('dataDiskArray')),0),4,parameters('dataDiskArray')[copyIndex('dataDisks')].diskSizeGB)]",
                                    "caching": "[if(equals(length(parameters('dataDiskArray')),0),'none',parameters('dataDiskArray')[copyIndex('dataDisks')].caching)]",
                                    "managedDisk": {
                                        "storageAccountType": "[if(equals(length(parameters('dataDiskArray')),0),'Standard_LRS',parameters('dataDiskArray')[copyIndex('dataDisks')].storageAccountType)]"
                                    }
                                }
                            }
                        ]
                    },
                    "resources": [
                        // Linux server and related resources
                        {
                            "type": "Microsoft.Network/networkInterfaces",
                            "apiVersion": "2020-03-01",
                            "name": "[concat(parameters('virtualMachinesName'),'_NIC1')]",
                            "location": "[parameters('location')]",
                            "properties": {
                                "ipConfigurations": [
                                    {
                                        "name": "ipconfig1",
                                        "properties": {
                                            "privateIPAllocationMethod": "Dynamic",
                                            "subnet": {
                                                "id": "[variables('subnetId')]"
                                            },
                                            "primary": true,
                                            "privateIPAddressVersion": "IPv4"
                                        }
                                    }
                                ],
                                "dnsSettings": {
                                    "dnsServers": [
                                    ]
                                },
                                "enableAcceleratedNetworking": false,
                                "enableIPForwarding": false
                            }
                        },
                        {
                            "type": "Microsoft.Compute/virtualMachines",
                            "apiVersion": "2019-07-01",
                            "name": "[parameters('virtualMachinesName')]",
                            "location": "[parameters('location')]",
                            "dependsOn": [
                                "[resourceId('Microsoft.Network/networkInterfaces', concat(parameters('virtualMachinesName'),'_NIC1'))]"
                            ],
                            "properties": {
                                "hardwareProfile": {
                                    "vmSize": "[parameters('virtualMachinesSize')]"
                                },
                                "storageProfile": {
                                    "imageReference": {
                                        "id": "[variables('imageId')]"
                                    },
                                    "osDisk": {
                                        "osType": "Linux",
                                        "name": "[concat(parameters('virtualMachinesName'), '_OsDisk')]",
                                        "createOption": "FromImage",
                                        "caching": "ReadWrite",
                                        "managedDisk": {
                                            "StorageAccountType": "Standard_LRS"
                                        }
                                    },
                                    "dataDisks": "[if(equals(length(parameters('dataDiskArray')),0),json('null'),variables('dataDisks'))]"
                                },
                                "osProfile": {
                                    "computerName": "[parameters('virtualMachinesName')]",
                                    "adminUsername": "[parameters('adminUsername')]",
                                    "adminPassword": "[parameters('adminPassword')]",
                                    "linuxConfiguration": {
                                        "disablePasswordAuthentication": false,
                                        "provisionVMAgent": true
                                    },
                                    "secrets": [
                                    ]
                                },
                                "networkProfile": {
                                    "networkInterfaces": [
                                        {
                                            "id": "[resourceId('Microsoft.Network/networkInterfaces', concat(parameters('virtualMachinesName'),'_NIC1'))]"
                                        }
                                    ]
                                },
                                "diagnosticsProfile": {
                                    "bootDiagnostics": {
                                        "enabled": true,
                                        "storageUri": "[concat('https://', parameters('storageAccountsName'), '.blob.core.windows.net/')]"
                                    }
                                }
                            }
                        }
                    ]
                }

            }
        }
    ],
    "outputs": {
    }
}
StephenWeatherford commented 4 years ago

@jorgecotillo I get an unhandled exception from the validation code as well, repros in the shipped 0.10.0 version, although I'm seeing a different error:

Template validation failed: Internal error: Validation threw an exception: Unhandled exception during evaluating template language function 'resourceId' is not handled.

I'm using the following params file (maybe a difference in the params file is responsible for the different errors)? We shouldn't ever get unhandled exceptions in the validation code, though.

730.parameters.json:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "value": "a"
        },
        "vaultName": {
            "value": "b"
        },
        "secretName": {
            "value": "c"
        },
        "vaultResourceGroupName": {
            "value": "d"
        },
        "vaultSubscription": {
            "value": "e"
        },
        "adminUsername": {
            "value": "f"
        },
        "virtualNetworksName": {
            "value": "g"
        },
        "subnetName": {
            "value": "a"
        },
        "storageAccountsName": {
            "value": "b"
        },
        "galleriesExternalId": {
            "value": "c"
        },
        "galleryImageDefinitionName": {
            "value": "d"
        },
        "virtualMachinesName": {
            "value": "e"
        },
        "virtualMachinesSize": {
            "value": "Standard_B2s"
        },
        "vmCount": {
            "value": 1
        },
        "dataDiskArray": {
            "value": [
                {
                    "name": "datadisk1",
                    "lun": 0,
                    "createOption": "Empty",
                    "caching": "None",
                    "diskSizeGB": 1,
                    "storageAccountType": "Standard_LRS"
                }
            ]
        }
    }
}
StephenWeatherford commented 4 years ago

Probably related to #716

yeswps commented 4 years ago

@StephenWeatherford

I had since made multiple changes to the template file, you may try to use following new template file and new parameter file. It should generate this error in VSCode:

Template validation failed: Internal error: Validation threw an exception: The template function 'copyIndex' is not expected at this location. The function can only be used in a resource with copy specified. Please see https://aka.ms/arm-copy for usage details.

linux-vm-template.json

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "The location where the resources will be deployed."
            }
        },
        "vaultName": {
            "type": "string",
            "metadata": {
                "description": "The name of the keyvault that contains the secret."
            }
        },
        "secretName": {
            "type": "string",
            "metadata": {
                "description": "The name of the secret in key vault, this secret will be admin user password."
            }
        },
        "vaultResourceGroupName": {
            "type": "string",
            "defaultValue": "[resourceGroup().name]",
            "metadata": {
                "description": "The name of the resource group that contains the keyvault."
            }
        },
        "vaultSubscription": {
            "type": "string",
            "defaultValue": "[subscription().subscriptionId]",
            "metadata": {
                "description": "The name of the subscription that contains the keyvault."
            }
        },
        "adminUsername": {
            "type": "string",
            "metadata": {
                "description": "admin user name"
            }
        },
        "virtualNetworksName": {
            "type": "string",
            "metadata": {
                "description": "virtual network name"
            }
        },
        "subnetName": {
            "type": "string",
            "metadata": {
                "description": "subnet name"
            }
        },
        "enableAcceleratedNetworking": {
            "type": "bool",
            "defaultValue": false,
            "metadata": {
                "description": "If the network interface is accelerated networking enabled."
            }
        },
        "storageAccountsName": {
            "type": "string",
            "metadata": {
                "description": "Provide storage account name for diagnostic logging"
            }
        },
        "galleriesExternalId": {
            "type": "string",
            "metadata": {
                "description": "Provide resource id of shared image gallery"
            }
        },
        "galleryImageDefinitionName": {
            "type": "string",
            "metadata": {
                "description": "Provide image defination name in shared image gallery"
            }
        },
        "virtualMachinesName": {
            "type": "string",
            "metadata": {
                "description": "Provide virtual machine name"
            }
        },
        "virtualMachinesSize": {
            "type": "string",
            "defaultValue": "Standard_B2s",
            "metadata": {
                "description": "Provide virtual machine size"
            }
        },
        "vmCount": {
            "type": "int",
            "defaultValue": 1,
            "metadata": {
                "description": "Number of VMs to be deployed"
            }
        },
        "osDiskSizeGB" : {
            "type": "int",
            "defaultValue": 128,
            "metadata": {
               "description": "OS Disk size in GB"
            }
        },
        "osDiskStorageAccountType": {
            "type": "string",
            "defaultValue": "Standard_LRS",
            "metadata": {
               "description": "OS Disk storage account type, Possible values include: 'Standard_LRS', 'Premium_LRS', 'StandardSSD_LRS', 'UltraSSD_LRS'"
            }
        },
        "dataDiskArray": {
            "metadata": {
                "diskSizeGB": "Disk size in GB",
                "storageAccountType": "Possible values include: 'Standard_LRS', 'Premium_LRS', 'StandardSSD_LRS', 'UltraSSD_LRS'",
                "caching": "Possible values include: 'ReadWrite','ReadOnly','None' By default, disk caching is 'ReadWrite' for the OS disk and 'None' for data disks. ",
                "exampleArray": [
                    {
                        "diskSizeGB": 4,
                        "storageAccountType": "Standard_LRS",
                        "caching": "None"
                    },
                    {
                        "diskSizeGB": 8,
                        "storageAccountType": "Premium_LRS",
                        "caching": "ReadWrite"
                    }
                ]
            },
            "type": "array",
            "defaultValue": [
            ]
        }
    },
    "variables": {
    },
    "resources": [
        {
            "name": "[if(greater(parameters('vmCount'),1),concat(parameters('virtualMachinesName'),copyIndex('vmCopy',1)),parameters('virtualMachinesName'))]",
            "copy": {
                "name": "vmCopy",
                "count": "[parameters('vmCount')]"
            },
            "apiVersion": "2019-10-01",
            "type": "Microsoft.Resources/deployments",
            "properties": {
                "expressionEvaluationOptions": {
                    "scope": "inner"
                },
                "mode": "Incremental",
                "parameters": {
                    "location": {
                        "value": "[parameters('location')]"
                    },
                    "adminUsername": {
                        "value": "[parameters('adminUsername')]"
                    },
                    "adminPassword": {
                        "reference": {
                            "keyVault": {
                                "id": "[resourceId(parameters('vaultSubscription'), parameters('vaultResourceGroupName'), 'Microsoft.KeyVault/vaults', parameters('vaultName'))]"
                            },
                            "secretName": "[parameters('secretName')]"
                        }
                    },
                    "virtualNetworksName": {
                        "value": "[parameters('virtualNetworksName')]"
                    },
                    "subnetName": {
                        "value": "[parameters('subnetName')]"
                    },
                    "enableAcceleratedNetworking": {
                        "value": "[parameters('enableAcceleratedNetworking')]"
                    },
                    "storageAccountsName": {
                        "value": "[parameters('storageAccountsName')]"
                    },
                    "galleriesExternalId": {
                        "value": "[parameters('galleriesExternalId')]"
                    },
                    "galleryImageDefinitionName": {
                        "value": "[parameters('galleryImageDefinitionName')]"
                    },
                    "virtualMachinesName": {
                        "value": "[if(greater(parameters('vmCount'),1),concat(parameters('virtualMachinesName'),copyIndex('vmCopy',1)),parameters('virtualMachinesName'))]"
                    },
                    "virtualMachinesSize": {
                        "value": "[parameters('virtualMachinesSize')]"
                    },
                    "osDiskSizeGB": {
                        "value" : "[parameters('osDiskSizeGB')]"
                    },
                    "osDiskStorageAccountType": {
                        "value": "[parameters('osDiskStorageAccountType')]"
                    },
                    "dataDiskArray": {
                        "value": "[parameters('dataDiskArray')]"
                    }
                },
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "location": {
                            "type": "string"
                        },
                        "virtualNetworksName": {
                            "type": "String"
                        },
                        "subnetName": {
                            "type": "string"
                        },
                        "enableAcceleratedNetworking": {
                            "type": "bool"
                        },
                        "storageAccountsName": {
                            "type": "String"
                        },
                        "galleriesExternalId": {
                            "type": "String"
                        },
                        "galleryImageDefinitionName": {
                            "type": "string"
                        },
                        "adminUsername": {
                            "type": "string"
                        },
                        "adminPassword": {
                            "type": "securestring"
                        },
                        "virtualMachinesName": {
                            "type": "String"
                        },
                        "virtualMachinesSize": {
                            "type": "string"
                        },
                        "osDiskSizeGB": {
                            "type": "int"
                        },
                        "osDiskStorageAccountType": {
                            "type": "string"
                        },
                        "dataDiskArray": {
                            "type": "array"
                        }

                    },
                    "variables": {
                        "subnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), parameters('subnetName'))]",
                        "imageId": "[concat(parameters('galleriesExternalId'), '/images/',parameters('galleryImageDefinitionName'))]",
                        "copy": [
                            {
                                "name": "dataDisks",
                                "count": "[if(equals(length(parameters('dataDiskArray')),0),1, length(parameters('dataDiskArray')))]",
                                "input": {
                                    "name": "[concat(parameters('virtualMachinesName'),'_DataDisk',copyIndex('dataDisks',1))]",
                                    "lun": "[if(equals(length(parameters('dataDiskArray')),0),0, copyIndex('dataDisks'))]",
                                    "createOption": "Empty",
                                    "diskSizeGB": "[if(equals(length(parameters('dataDiskArray')),0),4,parameters('dataDiskArray')[copyIndex('dataDisks')].diskSizeGB)]",
                                    "caching": "[if(equals(length(parameters('dataDiskArray')),0),'none',parameters('dataDiskArray')[copyIndex('dataDisks')].caching)]",
                                    "managedDisk": {
                                        "storageAccountType": "[if(equals(length(parameters('dataDiskArray')),0),'Standard_LRS',parameters('dataDiskArray')[copyIndex('dataDisks')].storageAccountType)]"
                                    }
                                }
                            }
                        ]
                    },
                    "resources": [
                        // Linux server and related resources
                        {
                            "type": "Microsoft.Network/networkInterfaces",
                            "apiVersion": "2020-03-01",
                            "name": "[concat(parameters('virtualMachinesName'),'_NIC1')]",
                            "location": "[parameters('location')]",
                            "properties": {
                                "ipConfigurations": [
                                    {
                                        "name": "ipconfig1",
                                        "properties": {
                                            "privateIPAllocationMethod": "Dynamic",
                                            "subnet": {
                                                "id": "[variables('subnetId')]"
                                            },
                                            "primary": true,
                                            "privateIPAddressVersion": "IPv4"
                                        }
                                    }
                                ],
                                "dnsSettings": {
                                    "dnsServers": [
                                    ]
                                },
                                "enableAcceleratedNetworking": "[parameters('enableAcceleratedNetworking')]",
                                "enableIPForwarding": false
                            }
                        },
                        {
                            "type": "Microsoft.Compute/virtualMachines",
                            "apiVersion": "2019-07-01",
                            "name": "[parameters('virtualMachinesName')]",
                            "location": "[parameters('location')]",
                            "dependsOn": [
                                "[resourceId('Microsoft.Network/networkInterfaces', concat(parameters('virtualMachinesName'),'_NIC1'))]"
                            ],
                            "properties": {
                                "hardwareProfile": {
                                    "vmSize": "[parameters('virtualMachinesSize')]"
                                },
                                "storageProfile": {
                                    "imageReference": {
                                        "id": "[variables('imageId')]"
                                    },
                                    "osDisk": {
                                        "osType": "Linux",
                                        "name": "[concat(parameters('virtualMachinesName'), '_OsDisk')]",
                                        "createOption": "FromImage",
                                        "caching": "ReadWrite",
                                        "diskSizeGB": "[parameters('osDiskSizeGB')]",
                                        "managedDisk": {
                                            "StorageAccountType": "[parameters('osDiskStorageAccountType')]"
                                        }
                                    },
                                    "dataDisks": "[if(equals(length(parameters('dataDiskArray')),0),json('null'),variables('dataDisks'))]"
                                },
                                "osProfile": {
                                    "computerName": "[parameters('virtualMachinesName')]",
                                    "adminUsername": "[parameters('adminUsername')]",
                                    "adminPassword": "[parameters('adminPassword')]",
                                    "linuxConfiguration": {
                                        "disablePasswordAuthentication": false,
                                        "provisionVMAgent": true
                                    },
                                    "secrets": [
                                    ]
                                },
                                "networkProfile": {
                                    "networkInterfaces": [
                                        {
                                            "id": "[resourceId('Microsoft.Network/networkInterfaces', concat(parameters('virtualMachinesName'),'_NIC1'))]"
                                        }
                                    ]
                                },
                                "diagnosticsProfile": {
                                    "bootDiagnostics": {
                                        "enabled": true,
                                        "storageUri": "[concat('https://', parameters('storageAccountsName'), '.blob.core.windows.net/')]"
                                    }
                                }
                            }
                        }
                    ]
                }

            }
        }
    ],
    "outputs": {
    }
}

linux-vm-template.parameters.json

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "value": "southcentralus"
    },
    "vaultName": {
      "value": "vaultName"
    },
    "secretName": {
      "value": "secretName"
    },
    "virtualNetworksName": {
      "value": "vnetName"
    },
    "subnetName": {
      "value": "subnetName"
    },

    "storageAccountsName": {
      "value": "storageAccountsName"
    },

    "galleriesExternalId": {
      "value": "galleriesExternalId"
    },
    "GalleryImageDefinitionName": {
      "value": "GalleryImageDefinitionName"
    },
    "adminUsername": {
      "value": "adminUsername"
    },
    "virtualMachinesName": {
      "value": "virtualMachinesName"
    },
    "virtualMachinesSize": {
      "value": "virtualMachinesSize"
    },
    "vmCount": {
      "value": 1
    }
  }
}
mvaferreira commented 4 years ago

I have the exact same error, when trying to create https://github.com/mvaferreira/armtemplates/blob/master/101-rds-deployment-full-ha/azuredeploy.json . My guess is that this is due to nested deployment and scope "inner", this extension doesn't even suggest you to use the "expressionEvaluationOptions".

"expressionEvaluationOptions": { "scope": "inner" },

StephenWeatherford commented 4 years ago

@mvaferreira Thanks for letting us know. You can try the alpha with nested template support here if you'd like: https://github.com/microsoft/vscode-azurearmtools/issues/719#issuecomment-631615905. This bug was entered against that alpha release (we're working on it).

expressionEvaluationOptions is not suggested by the extension because of a bug in the Azure schemas (see https://github.com/microsoft/vscode-azurearmtools/issues/714, cc @neilpeterson ).

mvaferreira commented 4 years ago

Hi @StephenWeatherford , I am now using 0.10.1-alpha and now it doesn't show all the other errors, but this one, at the beginning of the template:

image

I cannot find anywhere in the file, which 'copyIndex' it is talking about, since I am using many. It looks like a validation cache or something like that. If I copy this file to other location, it doesn't show any error at all. I have the same file at other location, which was also previously validated by the extension, that show the same error.

Is there a way to clear this cache, or should reinstall vscode?

I am using file https://github.com/mvaferreira/armtemplates/blob/master/101-rds-deployment-full-ha/azuredeploy.json

StephenWeatherford commented 4 years ago

@mvaferreira There is no validation cache, at the moment I think any copyIndex inside a nested template causes problems. @jorgecotillo is working on that.

@jorgecotillo It's also odd that there's no error location.

jorgecotillo commented 4 years ago

With the latest version I am not seeing this particular error instead I found a different one which was related to KeyVault reference not recognized inside the inner scope of a nested template. I have the fix in place and will submit a PR soon.

StephenWeatherford commented 4 years ago

added validation tests

StephenWeatherford commented 4 years ago

@jorgecotillo This bug still repros with the new bits:

1) Open https://raw.githubusercontent.com/mvaferreira/armtemplates/master/101-rds-deployment-full-ha/azuredeploy.json 2) Use this param file:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "projectName": {
            "value": "proj1"
        },
        "adminUser": {
            "value": "admin"
        },
        "adminPasswd": {
            "value": "mypassword"
        }
    }
}

!) Template validation failed: The template function 'copyIndex' is not expected at this location. The function can only be used in a resource with copy specified. Please see https://aka.ms/arm-copy for usage details.

NOTE: There is no line/col info in the error, and there are quite a few 'copyIndex' functions in the template.

StephenWeatherford commented 4 years ago

NOTE: The bad error messages were fixed, but not the copyIndex issue.

jorgecotillo commented 4 years ago

Thanks @StephenWeatherford I was able to repro the issue and was able to fix it, it was related to the expansion of copy function. The fix will be in v1.0.20