Issue with Packer Variable shared image gallery destination

I am trying to integrate the use of Shared Image Galleries into what was a working capture process using Packer in Azure DevOps for a WVD Image. Previously a segment of this code created a gold VM and captured into a normal Resource Group for use. Now id like to copy it to a Shared Image Gallery aswell

Having worked through a few examples I believe I am there or there-about with the code however when I execute this in a pipeline I get the following error:

Template validation failed. Errors are shown below.

Errors validating build ‘azure-arm’. 1 error(s) occurred:

  • unknown configuration key: “shared_image_gallery_destination”
    ##[error]Packer validate command failed. This could happen if task does not support packer version.
    Finishing: Build Canary image v20h2

I have tried to simplify out my JSON and have less variables etc but it does not seem to matter. I have tried Packer version 1.7.0 and dropped down multiple versions to no avail.

I have included my JSON minus a couple of bits below as there is not really anything data pertinent other than variable calls.

Would appreciate any assistance but it just does not seem the like the Shared Image Gallery destination parameter but the website article suggests this is right for capturing the image and copying it to the SIG.

Code Start
{
“variables”: {
“client_id”: “”,
“client_secret”: “”,
“AppInstallStorageAccountName”: “”,
“AppInstallStorageAccountKey”: “”,

"az_tenant_id": "{{env `az_tenant_id`}}",
"subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}",
"wvd_goldimage_rg": "{{env `wvd_goldimage_rg`}}",

"SharedImageGalleryRG": "{{env `wvd_SharedGallery_rg`}}",
"SharedGalleryName": "{{env `wvd_SharedGalleryName`}}",
"SharedImageVersion": "{{env `wvd_SharedImageVersion`}}",
"wvdmanaged_image_name": "{{env `wvd_ManagedImageName`}}",

"packaged_app_installs_path": "{{env `packaged_app_installs_path`}}",

"Build_DefinitionName": "{{env `Build_DefinitionName`}}",
"Build_BuildNumber": "{{env `Build_BuildNumber`}}",
"Release_Branch": "{{env `Release_Branch`}}",
  "Redstone_Release": "20H2"

},
“builders”: [
{
“type”: “azure-arm”,

  "client_id": "{{user `client_id`}}",
  "client_secret": "{{user `client_secret`}}",
  "tenant_id": "{{user `az_tenant_id`}}",
  "subscription_id": "{{user `subscription_id`}}",

  "os_type": "Windows",
  "image_publisher": "MicrosoftWindowsDesktop",
  "image_offer": "Windows-10",
  "image_sku": "20h2-evd",
  "location": "UK South",
  "vm_size": "Standard_B2S",

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

  "shared_image_gallery_destination": {
    "resource_group": "{{user `SharedImageGalleryRG`}}",
    "gallery_name": "{{user `SharedGalleryName`}}",
    "image_name": "{{user `wvdmanaged_image_name`}}-Build{{user `Build_BuildNumber`}}",
    "image_version": "{{user `SharedImageVersion`}}",
    "replication_regions": "northeurope"
  },

  "managed_image_name": "{{user `wvdmanaged_image_name`}}-Build{{user `Build_BuildNumber`}}",
  "managed_image_resource_group_name": "{{user `wvd_goldimage_rg`}}",

  

  "temp_resource_group_name": "###",
  "virtual_network_name": "###",
  "virtual_network_subnet_name": "###",
  "private_virtual_network_with_public_ip": "True",
  "virtual_network_resource_group_name": "###",


  "azure_tags": {
    "Project": "aodevwvd"
  },

  

  "async_resourcegroup_delete":true
}

],
“provisioners”: [
{
“type”: “powershell”,
“inline”: [
“$ErrorActionPreference=‘Stop’”,

      "Write-Host \"Preparing to establish connection to Azure File Share\"",
      "Import-Module -Name Smbshare -Force -Scope Local",
      "$Usr='Azure\\'+\"{{user `AppInstallStorageAccountName`}}\"",
      "Write-Host \"{{user `packaged_app_installs_path`}}\" -Username \"$Usr\" -Password \"{{user `AppInstallStorageAccountKey`}}\"",
      "New-SmbMapping -LocalPath W: -RemotePath \"{{user `packaged_app_installs_path`}}\" -Username \"$Usr\" -Password \"{{user `AppInstallStorageAccountKey`}}\"",
      "Write-Host \"'W:' drive has been successfully mapped, preparing for application installation\"" 
    ]
},

{
  "type": "powershell",
  "inline": [
    " # NOTE: Entering SYSPREP Phase for Golden Image.",
    
    "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 /quiet /quit",
    "while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10  } else { break } }",
    " # NOTE: Completed SYSPREP Phase for Golden Image. Closing out...",
    "Write-Host \"Completed the WVD Golden Capture Process, closing out.\""
  ]
}

]
}
Code End

This feature has been available since v1.4.3. (PR is here: Fix bug while publishing SIG destination id for every managed image by amydutta · Pull Request #7837 · hashicorp/packer · GitHub)

I copied and pasted your config and can’t reproduce; the only validation errors I get are related to the env vars and ### vars that you stripped out; when I clean up the quotes and add valid strings to temp_resource_group_name and managed_image_resource_group_name, the validation passes.

Thanks for replying

So, I managed to solve the issue. After going through step by step, I noticed that under the Build Machine Image step (directly under the packer step in the pipeline) under advanced, there is also an area to specify a version of Packer!

It looks like this was never being updated when I updated the Packer step with the various different versions i tried!

ARGH!!! Well its done now and a lesson learnt… [insert sigh]

1 Like