Azure VM creation failed using downloaded template (The entity name 'vmImageName' is invalid according to its validation rule)

Christophe DELARUE 96 Reputation points

(Already asked on stackoverflow

I want to create a vm on azure using az cli. So I created interactively a VM and downloaded the template and its parameters. I added some missing parameters, the final script is

az deployment group create --resource-group my-rg --template-file ./azure-32Go.template.json --parameters @./azure-32Go.template.parameters --parameters publicIpAddressName=my-ip networkInterfaceName=my-nic adminPublicKey="$(cat ~/.ssh/" imageName=MsOps-Demo1-image-20210212-175858 --debug

I get an error

msrestazure.azure_exceptions.CloudError: Azure Error: DeploymentFailed
Message: At least one resource deployment operation failed. Please list deployment operations for details. Please see for usage details.
Exception Details: > Error Code: BadRequest
Message: {'error': {'code': 'InvalidParameter', 'message': "The entity name 'vmImageName' is invalid according to its validation rule: ^[^\W][\w-.]{0,79}(?<![-.])$.", 'target': 'vmImageName'}}

Googling did not point me to someone to get the same issue. I looked in azur portal Resource Group / Activity log to look at more information, but I only see the same above issue with no more information

How can I fix my code ?

My template files :


Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,373 questions
{count} votes

Accepted answer
  1. Christophe DELARUE 96 Reputation points

    I auto answer this question.

    I have redone the whole process, and starting the vm with the template works fine.

    I wanted to set a specific image name. I added a parameter imageName

    Now I updated the template.json by adding a parameter

    "parameters": {
    "location": {
    "type": "string"
    "imageName": {
    "type": "string"

    "networkInterfaceName": {

    Updated where it is used

    "storageProfile": {
    "osDisk": {
    "createOption": "fromImage",
    "managedDisk": {
    "storageAccountType": "[parameters('osDiskType')]"
    "imageReference": {
    "id": "/subscriptions/14b6e880-753e-4a5f-8618-c0786702aa1c/resourceGroups/MsOps-Horizon-rg/providers/Microsoft.Compute/images/[parameters('imageName')]"

    But when doing the creation process fails with the same reason

    Deployment failed. Correlation ID: 39b18e50-ff0d-4ecd-a3e8-e40b988a341b. {
    "error": {
    "code": "InvalidParameter",
    "message": "The entity name 'vmImageName' is invalid according to its validation rule: ^[^\W][\w-.]{0,79}(?<![-.])$.",
    "target": "vmImageName"
    Creation of vm failed

    My workaround is therefore to do a sed in the template.json to insert the image name I want :(

    My guess is that the [parameter('imageName')] is not expanded early enough which makes the process fails as the name does not match the matching rule

    0 comments No comments

0 additional answers

Sort by: Most helpful