Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, September 27, 2019 5:51 AM
Hi,
I am trying to move VM image from one RG to Shared Image gallery using packer. But am getting the following error.
The Shared Gallery Image to which to publish the managed image version to does not exist in the resource group.
Kindly suggest me any solution for this.
Please find the script below.
{
"builders": [{
"type": "azure-arm",
"client_id": "",
"client_secret": "",
"subscription_id": "",
"tenant_id": "",
"os_type": "Windows",
"image_publisher": "MicrosoftWindowsServer",
"image_offer": "WindowsServer",
"image_sku": "2012-R2-Datacenter",
"communicator": "winrm",
"winrm_use_ssl": "true",
"winrm_insecure": "true",
"winrm_timeout": "5m",
"winrm_username": "packer",
"managed_image_resource_group_name": "shivu",
"managed_image_name": "myPackerImg12",
"shared_image_gallery_destination": {
"resource_group":"shivu",
"gallery_name": "sharedimage",
"image_name": "test",
"image_version": "1.0",
"replication_regions": ["South India"]
},
"azure_tags": {
"dept": "Engineering",
"task": "Image deployment"
},
"location": "East US",
"vm_size": "Standard_D2_v2"
}],
"provisioners": [{
"type": "powershell",
"inline": [
"Add-WindowsFeature Web-Server",
"& $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 } }"
]
}]
}
All replies (10)
Friday, September 27, 2019 12:45 PM
Hi Karthikeya,
You dont have the shared image gallery "sharedimage" in the resource group "shivu".
Create a new shared image gallery in the resource group.
You can follow this document to create one. Two components has to be created.
- Image gallery
- image definition
Image version will be given in the packer template
While creating the above components, Give the same name which you gave in the template.
After creating the shared image gallery, Then execute the packer build again.
This document describes the process of building an image with packer.
Note:
We have a service called Azure image builder (currently in preview), which uses packer under the hood is also available.
Monday, September 30, 2019 6:23 AM
Hi Jakaruna,
I have created the shared image gallery and followed the same steps but still getting the error.
Regards,
Karthik.T
Monday, September 30, 2019 6:37 AM
Jakaruna,
I am able to create the image. The error which I am getting is to move the created image to shared image gallery.
is there any other command to do this. Below mentioned is the command which am using.
"shared_image_gallery_destination": {
"resource_group":"shivu",
"gallery_name": "sharedimage",
"image_name": "test",
"image_version": "1.0",
"replication_regions": ["South India"]
},
Tuesday, October 1, 2019 6:52 AM
Hi,
If the shared image gallery is not there, Packer will complain in the initial stage(Before creation the image)
Are you saying that the image creation succeeds and fails while moving the image to the shared image gallery?
When i tried, Packer gave the error immediately .
Tuesday, October 1, 2019 10:34 AM
HI,
How much time it takes from the time you gave the "packer build" command and the time it gives that error?
Thursday, October 3, 2019 8:44 AM
Hi,
I am getting the error immediately after running the packer build command. But the shared image gallery is there in the resource group.
When I created the image definition manually and run the command then the image version got created.
If this is the case do we need create the image definition manually every time when we want to move image.
Is there any script to create the image definition.
Thanks,
Karthik.T
Friday, October 4, 2019 10:03 AM
Hi,
You need to create the image definition as well. One image definition can have many versions.
You can use the powershell or cli to create many items in a loop.
Packer wont create the image definitions for us. It will only create the new version and place the image there.
I didnt understand about moving the image. Please explain if i am missing something.
Packer creates the new image and uploads that new image to the shared image gallery. Packer wont move the existing image.
Monday, October 7, 2019 11:30 AM
Hello Karthikeya,
Any update on the issue?
Just checking if you got a chance to see the response from Jakaruna.
If the suggested answer helped you solve your query, do click on "Mark as Answer" and "Up-Vote" on the answer that helped you for the benefit of other community members.
Thanks.
Wednesday, October 16, 2019 9:05 AM
Hi,
Thanks for the input. I was trying to create the Image definition using packer. Now I will create it using Powershell and execute the packer.
Sorry for late reply.
Regards,
Karthik.T
Thursday, October 17, 2019 4:57 AM
Try that out and let us know