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

Christophe DELARUE 96 Reputation points
2021-02-15T13:27:18.943+00:00

(Already asked on stackoverflow https://stackoverflow.com/questions/66206911/azure-vm-creation-failed-using-downloaded-template-the-entity-name-vmimagename)

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/id_rsa.pub)" 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 https://aka.ms/DeployOperations 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 :

68243-azure-32gotemplateparameters.txt
68228-azure-32gotemplatejson.txt

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

Accepted answer
  1. Christophe DELARUE 96 Reputation points
    2021-02-15T16:29:24.777+00:00

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.