Packer azure-arm:找不到托管图像资源组

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

我是 Packer 的新手,我一直在尝试按照本指南在 Azure 映像上构建我的第一个 Packer - https://docs.microsoft.com/en-us/azure/virtual-machines/windows/build-image-with-packer

我没有完全按照指南进行操作,因为我已经设置了 Azure 订阅和资源组。但是现在,当我尝试构建我的 Packer 映像时,出现以下错误

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

通过阅读文档,它指出唯一的要求是资源组已经存在,正如我在我的 Azure 门户中看到的那样。

我的打包程序 json 文件遵循如下所示的指南中的文件,感谢您的帮助

    {
  "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"
    ]
  }]
}

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

根据此错误消息,您似乎没有替换 json 文件中的 资源组名称

"managed_image_resource_group_name": "myResourceGroup",

我们应该用您的现有资源组名称替换那个myResourceGroup,像这样:

   "managed_image_resource_group_name": "jasonpacker",

我们还应该替换 client_idclient_secrettenant_idsubscription_idobject_id.

完成后,我们可以在您现有的资源组中找到图片:

Packer 存在一个未解决的问题,当 client_id / client_secret 对不匹配时会显示此错误,有关详细信息,请参阅 here

这发生在我身上,因为我的服务主体没有足够的权限读取资源组。

确保您拥有正确的权限,这应该会创建一个正确的服务主体:

az ad sp create-for-rbac --role Contributor --name sp-packer-001