What Was the Problem?
I recently had to create a VM image for an Azure scale-set using packer. Overall, the experience was great… but getting off the ground took me about an hour. This was because most tutorials/examples assume you have contributor access to the whole subscription, but I wanted to do it with a service principal that just had access to a specific resource group.
Working Configuration
Basically, you just need the right combination (or lack-there-of) of fields.
The tricky ones to get right were the combination of build_resource_group_name, managed_image_resource_group_name, and managed_image_name while leaving out location.
There was a Git Hub issue chain on this (https://github.com/hashicorp/packer/issues/5873) that went on for a very long time before someone finally worked out that you had to leave out location when you wanted to do this without subscription level contributor access.
Here is a reference config file that works if you populate your details:
{ "builders":[ { "type":"azure-arm", "client_id":"your-client-id", "client_secret":"your-client-secret", "tenant_id":"your-tenant-id", "subscription_id":"your-subscription", "build_resource_group_name":"your-existing-rg", "managed_image_resource_group_name":"your-existing-rg", "managed_image_name":"your-result-output-image-name", "os_type":"Linux", "image_publisher":"OpenLogic", "image_offer":"CentOS", "image_sku":"7.5", "azure_tags":{ "ApplicationName":"Some Sample App" }, "vm_size":"Standard_D2s_v3" } ], "provisioners":[ { "execute_command":"chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", "inline":[ "yum -y install haproxy-1.5.18-8.el7", "/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync" ], "inline_shebang":"/bin/sh -x", "type":"shell" } ] }