Search code examples
azurepacker

Packer azure-arm: Cannot locate the managed image resource group


I am new to Packer and I have been trying to build my first packer on Azure image following this guide - https://learn.microsoft.com/en-us/azure/virtual-machines/windows/build-image-with-packer

I did not follow the guide exactly as I already had a an Azure Subscription and resource group set up. But now when I attempt to build my Packer image I get the following error

Build 'azure-arm' errored: Cannot locate the managed image resource group myResourceGroup

From reading through the docs it states the only requirement is that the resource group already exist, which it does as I can see it in my Azure portal.

My packer json file follows the one from the guide which is shown below, any help appreciated

    {
  "builders": [{
    "type": "azure-arm",

    "client_id": "0831b578-8ab6-40b9-a581-9a880a94aab1",
    "client_secret": "P@ssw0rd!",
    "tenant_id": "72f988bf-86f1-41af-91ab-2d7cd011db47",
    "subscription_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
    "object_id": "a7dfb070-0d5b-47ac-b9a5-cf214fff0ae2",

    "managed_image_resource_group_name": "myResourceGroup",
    "managed_image_name": "myPackerImage",

    "os_type": "Windows",
    "image_publisher": "MicrosoftWindowsServer",
    "image_offer": "WindowsServer",
    "image_sku": "2016-Datacenter",

    "communicator": "winrm",
    "winrm_use_ssl": "true",
    "winrm_insecure": "true",
    "winrm_timeout": "3m",
    "winrm_username": "packer",

    "azure_tags": {
        "dept": "Engineering",
        "task": "Image deployment"
    },

    "location": "East US",
    "vm_size": "Standard_DS2_v2"
  }],
  "provisioners": [{
    "type": "powershell",
    "inline": [
      "Add-WindowsFeature Web-Server",
      "if( Test-Path $Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml ){ rm $Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml -Force}",
      "& $Env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /shutdown /quiet"
    ]
  }]
}

Solution

  • Build 'azure-arm' errored: Cannot locate the managed image resource group myResourceGroup

    According to this error message, it seems you have not replace your resource group name in that json file.

    "managed_image_resource_group_name": "myResourceGroup",
    

    We should replace that myResourceGroup with your existing resource group name, like this:

       "managed_image_resource_group_name": "jasonpacker",
    

    Also we should replace client_id, client_secret, tenant_id, subscription_id and object_id.

    After that complete, we can find the image in your existing resource group:

    enter image description here