Azure Packer build from custom image - Parameter 'osProfile' is not allowed

Hi Packer Community,


Build 'azure-arm.centos-base' errored after 14 minutes 1 second: Code="DeploymentFailed" Message="At least one resource deployment operation failed. Please list deployment operations for details. Please see for usage details." Details=[{"code":"BadRequest","message":"{\r\n  \"error\": {\r\n    \"code\": \"InvalidParameter\",\r\n    \"message\": \"Parameter 'osProfile' is not allowed.\",\r\n    \"target\": \"osProfile\"\r\n  }\r\n}"}]

Please see template (1)

I am attempting to take a managed custom image which was created using the azure cli (2) and use it as my base image in packer. But I am getting the above Error on osProfile. I believe this is because I am using a ‘specialized’ type of image which already has ssh and authentication configured on the box and will NOT allow packer to specify a new username or password. To get around this I have tried to reuse an existing user build into the image as ‘ssh_username’ with ‘ssh_certificate_file’ but the Error is not resolved. Please let me know if there is any other information I can provide!

(1) template.pkr.hcl

source "azure-arm" "centos-base" {
  use_azure_cli_auth = true
  temp_resource_group_name = "dev-packer"
  location = "East US"
  os_type = "Linux"
  ssh_certificate_file = "~/.ssh/<existing_user_key>"
  ssh_username = "<existing_user>"

  managed_image_name = "centos-base-test"
  managed_image_resource_group_name = "***"
  vm_size = "Standard_B2s"

  shared_image_gallery {
    subscription   = "***"
    resource_group = "***"
    gallery_name   = "***"
    image_name     = "centos-base"
    image_version  = "1.0.1"

  shared_image_gallery_destination {
    subscription         = "***"
    resource_group       = "***"
    gallery_name         = "***"
    image_name           = "testingIT"
    image_version        = "1.0.0"
    replication_regions  = ["East US"]
    storage_account_type = "Standard_LRS"

build {
  sources = [""]
  provisioner "shell" {
    execute_command = "sudo -S env {{ .Vars }} {{ .Path }}" # Runs commands as root
    inline = [
      "mkdir -p /var/this/is/a/test",
      "yum upgrade -y"
    only = [""]

(2) Initial image create

az sig image-version create \
   --resource-group *** \
   --gallery-name *** \
   --gallery-image-definition *** \
   --gallery-image-version *** \
   --target-regions "***" "***" \
   --replica-count 1 \
   --managed-image "<my_VM>"

I am a beginner with Packer so please let me know if I have missed something in my explanation or if there is any simple way around this issue.
Thank you!

Maybe I missed it, but don’t you need to specify a communicator in the Source block?

  source "null.test" {
    ssh_host = "test"
    ssh_username = "me"
    communicator = "none"

Not sure if the ssh_host is required. You could also look at the VM.Properties JSON information to verify that the information you’re using in the template file matches the osProfile information?

Just taking a stab in the dark here, since I only use packer to build Windows templates, from scratch, from both Azure Images and AWS AMI’s from the provider.