0

I'm trying to deploy a VM from a custom image on Azure. I'm using the portal and Azure CLI.

When I create a VM from a product in the marketplace, everything goes smoothly. When I capture an image of the VM (going through the deallocation and generalizing process), and then try to deploy a VM from that image, it fails while creating the VM due to a "no plan" error.

I've been troubleshooting and it seems I need a template and parameters json file to specify how to deploy, but the documentation on this is scarce and I'm unsure how to configure these files and what part of them is the "plan". I can take an existing VM/resource group and download the template.json and paramater.json files, but trying to create a new VM with these files fails.

Does anyone have experience with this or knows where adequate documentation is?

Here is an example of the template.json file:

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "location": {
        "type": "string"
    },
    "networkInterfaceName": {
        "type": "string"
    },
    "networkSecurityGroupName": {
        "type": "string"
    },
    "networkSecurityGroupRules": {
        "type": "array"
    },
    "subnetName": {
        "type": "string"
    },
    "virtualNetworkId": {
        "type": "string"
    },
    "publicIpAddressName": {
        "type": "string"
    },
    "publicIpAddressType": {
        "type": "string"
    },
    "publicIpAddressSku": {
        "type": "string"
    },
    "virtualMachineName": {
        "type": "string"
    },
    "virtualMachineRG": {
        "type": "string"
    },
    "osDiskType": {
        "type": "string"
    },
    "virtualMachineSize": {
        "type": "string"
    },
    "adminUsername": {
        "type": "string"
    },
    "adminPassword": {
        "type": "secureString"
    },
    "diagnosticsStorageAccountName": {
        "type": "string"
    },
    "diagnosticsStorageAccountId": {
        "type": "string"
    }
},
"variables": {
    "nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]",
    "vnetId": "[parameters('virtualNetworkId')]",
    "subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]"
},
"resources": [
    {
        "name": "[parameters('networkInterfaceName')]",
        "type": "Microsoft.Network/networkInterfaces",
        "apiVersion": "2018-10-01",
        "location": "[parameters('location')]",
        "dependsOn": [
            "[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]",
            "[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName'))]"
        ],
        "properties": {
            "ipConfigurations": [
                {
                    "name": "ipconfig1",
                    "properties": {
                        "subnet": {
                            "id": "[variables('subnetRef')]"
                        },
                        "privateIPAllocationMethod": "Dynamic",
                        "publicIpAddress": {
                            "id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName'))]"
                        }
                    }
                }
            ],
            "networkSecurityGroup": {
                "id": "[variables('nsgId')]"
            }
        }
    },
    {
        "name": "[parameters('networkSecurityGroupName')]",
        "type": "Microsoft.Network/networkSecurityGroups",
        "apiVersion": "2018-08-01",
        "location": "[parameters('location')]",
        "properties": {
            "securityRules": "[parameters('networkSecurityGroupRules')]"
        }
    },
    {
        "name": "[parameters('publicIpAddressName')]",
        "type": "Microsoft.Network/publicIpAddresses",
        "apiVersion": "2018-08-01",
        "location": "[parameters('location')]",
        "properties": {
            "publicIpAllocationMethod": "[parameters('publicIpAddressType')]"
        },
        "sku": {
            "name": "[parameters('publicIpAddressSku')]"
        }
    },
    {
        "name": "[parameters('virtualMachineName')]",
        "type": "Microsoft.Compute/virtualMachines",
        "apiVersion": "2018-06-01",
        "location": "[parameters('location')]",
        "dependsOn": [
            "[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
        ],
        "properties": {
            "hardwareProfile": {
                "vmSize": "[parameters('virtualMachineSize')]"
            },
            "storageProfile": {
                "osDisk": {
                    "createOption": "fromImage",
                    "managedDisk": {
                        "storageAccountType": "[parameters('osDiskType')]"
                    }
                },
                "imageReference": {
                    "id": "/subscriptions/56640100-5e0e-4f37-9c73-d716e7306962/resourceGroups/Test-RG/providers/Microsoft.Compute/images/Test-VM-image-20190423094722"
                }
            },
            "networkProfile": {
                "networkInterfaces": [
                    {
                        "id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
                    }
                ]
            },
            "osProfile": {
                "computerName": "[parameters('virtualMachineName')]",
                "adminUsername": "[parameters('adminUsername')]",
                "adminPassword": "[parameters('adminPassword')]"
            },
            "diagnosticsProfile": {
                "bootDiagnostics": {
                    "enabled": true,
                    "storageUri": "[concat('https://', parameters('diagnosticsStorageAccountName'), '.blob.core.windows.net/')]"
                }
            }
        }
    }
],
"outputs": {
    "adminUsername": {
        "type": "string",
        "value": "[parameters('adminUsername')]"
    }
}

}

Here is an example of the parameters.json file:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "location": {
        "value": "westus"
    },
    "networkInterfaceName": {
        "value": "test-vm726"
    },
    "networkSecurityGroupName": {
        "value": "TestVMnsg114"
    },
    "networkSecurityGroupRules": {
        "value": []
    },
    "subnetName": {
        "value": "default"
    },
    "virtualNetworkId": {
        "value": "/subscriptions/56640100-5e0e-4f37-9c73-d716e7306962/resourceGroups/Test-RG/providers/Microsoft.Network/virtualNetworks/Test-RG-vnet"
    },
    "publicIpAddressName": {
        "value": "TestVMip568"
    },
    "publicIpAddressType": {
        "value": "Dynamic"
    },
    "publicIpAddressSku": {
        "value": "Basic"
    },
    "virtualMachineName": {
        "value": "Test-VM"
    },
    "virtualMachineRG": {
        "value": "Test-RG"
    },
    "osDiskType": {
        "value": "Premium_LRS"
    },
    "virtualMachineSize": {
        "value": "Standard_B2s"
    },
    "adminUsername": {
        "value": "clear"
    },
    "adminPassword": {
        "value": null
    },
    "diagnosticsStorageAccountName": {
        "value": "testcustomacc282828"
    },
    "diagnosticsStorageAccountId": {
        "value": "/subscriptions/56640100-5e0e-4f37-9c73-d716e7306962/resourceGroups/Test-RG/providers/Microsoft.Storage/storageAccounts/testcustomacc282828"
    }
}

}

1
  • I've learned a little more since posting. The "plan" information is only needed when deploying a marketplace solution, so since I'm deploying from a custom image I don't need it. However since I built my custom image on a marketplace solution, the template still has the marketplace solution as my base, and so it thinks I need a plan. I'm currently trying to build a custom ARM template to deploy my image, though that process is horrendously complicated and poorly documented.
    – cmeados
    Apr 19 '19 at 23:19
-1

Try adding the plan information like so:

    "imageReference": {
    "id": "/subscriptions/56640100-5e0e-4f37-9c73-d716e7306962/resourceGroups/Test-RG/providers/Microsoft.Compute/images/Test-VM-image-20190423094722",
    "publisher": "string",
    "offer": "string",
    "sku": "string",
    "version": "string"
  },

Even though it is a custom image, if it was built from a marketplace image it will still have the plan information tied to it.

https://docs.microsoft.com/en-us/azure/templates/microsoft.compute/2019-03-01/virtualmachines

8
  • Those resources are the first and only ones I came across as well, but they don't help with my use case, since I am deploying from a custom image.
    – cmeados
    Apr 19 '19 at 23:16
  • can you share your code so I can test?
    – Micah_MSFT
    Apr 22 '19 at 18:30
  • 1
    I put example code in the original post. This was made the same way I made my original image, and gets the same error.
    – cmeados
    Apr 23 '19 at 17:11
  • Updated the answer.
    – Micah_MSFT
    Apr 24 '19 at 17:17
  • So I should add the publisher, offer, sku, and version fields? My custom image doesn't have any of those properties. Did you test it and did that work?
    – cmeados
    Apr 24 '19 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.