0

I have created a ubuntu image by following code

{
  "builders": [{
    "type": "azure-arm",

    "subscription_id": "XXXXXX",XXXXXXXX
     "client_id":  "XXXXXXX",
     "client_secret": "06XXXXXXX",
     "tenant_id":  "41X",XXXXXX

    "managed_image_resource_group_name": "myResourceGroup",
    "managed_image_name": "myubuntuPackerImage1234",

    "os_type": "Linux",
    "image_publisher": "Canonical",
    "image_offer": "UbuntuServer",
    "image_sku": "16.04-LTS",


    "location": "East US",
    "vm_size": "Standard_DS2_v2"
  }],
  "provisioners": [{
    "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",
    "inline": [
      "apt-get update",
      "apt-get upgrade -y",
      "apt-get -y install nginx",

      "/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"
    ],
    "inline_shebang": "/bin/sh -x",
    "type": "shell"
  }]
}

packer build ubuntu.json

it will build successfully and output will be

OSType: Linux
ManagedImageResourceGroupName: myResourceGroup
ManagedImageName: packerimagewin2019up
ManagedImageId: /subscriptions/XXXXXXXXXX/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myubuntuPackerImage1234
ManagedImageLocation: eastus

I found one PR - https://github.com/hashicorp/packer/issues/3785 but in case of manage disk how will get url ?

if i run az image list it will not show you .vdf blob url how can i use above output to create new update on existing image myubuntuPackerImage1234 ?

sanjayparmar
  • 633
  • 8
  • 19

1 Answers1

1

As I understand it, you want to use an image you previously created with Packer, as the source image for running packer again right?

The example you reference won't work, because this example uses packer to create a VHD based disk image (this is the older method) whereas you are using managed images/disks and so do not have a URL in the same way as a VHD.

As far as I can tell, the only way to use an existing managed image with packer is to publish this image to a shared image gallery (you can do this manually, or as part of the packer build). You can then reference this image from the gallery using the tags, and the shared_image_gallery setting.

Alternatively, you could create your source image as VHD and then use the URL, but then you would be going back to the older method.

Sam Cogan
  • 38,736
  • 6
  • 78
  • 114
  • I used shared image gallery where ```"image_publisher": "MyOffer", "image_offer": "MyUbuntuServer", "image_sku": "My6.04-LTS",``` but when i search ```az vm image list --location southeastasia --offer MyUbuntuServer --all --output table``` blank result. Could you please help me to used shared image gallery details like above ? – sanjayparmar Dec 15 '19 at 13:03
  • Have you actually put your image in the shared image gallery? By default packer will just create the managed image, it won’t put it in a gallery – Sam Cogan Dec 15 '19 at 13:35
  • yes i have added already. its working after removing like image_publisher. thanks for pointing. – sanjayparmar Dec 15 '19 at 15:56
  • need to add following to create multiple version. ```"shared_image_gallery": { "subscription": "xxx-adxxx-444dxxxx-xxxxx", "resource_group": "myResourceGroup", "gallery_name": "packerubuntu", "image_name": "packer-ubuntu", "image_version": "0.0.1" }, "shared_image_gallery_destination": { "resource_group": "myResourceGroup", "gallery_name": "packerubuntu", "image_name": "packer-ubuntu", "image_version": "0.0.2", "replication_regions": ["eastus", "eastus2"] },``` – sanjayparmar Dec 15 '19 at 15:59
  • @sanjayparmar glad you got it sorted – Sam Cogan Dec 16 '19 at 15:41