hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.06k stars 3.33k forks source link

Packer image usable only in one AZ #8215

Open wrath-m opened 5 years ago

wrath-m commented 5 years ago

Overview of the Issue

The Packer provisioned image is available to use only in the availability zone used by Packer to deploy the instance. It seems to be related with the snapshot creation which is linked to the particular az used by Packer.

Packer version

./packer --version 1.4.3

Simplified Packer Buildfile

"builders": [
    {
        "type": "openstack",
        "image_name": "{{user `image_name`}}",
        "ssh_username": "{{user `username`}}",
        "source_image": "{{user `source_image`}}",
        "flavor": "{{user `flavor`}}",
        "ssh_ip_version": "4",
        "networks": "{{user `networks`}}",
        "metadata": [{"min_disk": "40"}, {"image_type": "image"}],
        "security_groups": "{{user `security_groups`}}"
    }
]

Details:

| properties | account_code='linux', __backup_id='', data_origin='instance,02571d51-1144-43f8-8aca-ac0e5aed2cb4', description='This image is provided by and supported by Orange Business Services. It is free, only the consumption is charged', image_provide='Orange Business Services', image_size='561299456', image_source_type='uds', imagetype='private', isregistered='true', originalimagename='671d11c3-7c4b-4010-9a19-68e5922e0869', __os_bit='64', os_type='Linux', os_version='CentOS 7.5 64bit', platform='CentOS', productcode='', __root_origin='file', support_diskintensive='true', support_highperformance='true', __support_kvm='true', support_xen='true', base_image_ref='', bdm_v2='True', block_device_mapping='[{"guest_format": null, "boot_index": 0, "device_type": null, "availability_zone": null, "no_device": null, "delete_on_termination": true, "snapshot_id": "f6413357-067c-4747-95c8-f742d287ca0d", "volume_type": null, "device_name": "/dev/vda", "disk_bus": null, "image_id": null, "source_type": "snapshot", "volume_ext_info": null, "volume_id": null, "destination_type": "volume", "extended_info": null, "volume_size": 40}]', csd_instance_uuid='8cce52ba-383a-4ec4-8d55-015f9a21eeac', destination_type='local', hw_firmware_type='bios', image_type='image', owner_project_name='eu-west-0', owner_user_name='test', root_device_name='/dev/vda', virtual_env_type='FusionCompute' |

I think changing the "destination_type" from volume to local in block_device_mapping[] would possibly solve this, but Packer doesn't seem to have a way to do that (as it doesn't satisfy the map[string]string type of metadata field).

SwampDragons commented 4 years ago

Hi, thanks for reaching out! I believe the final device's AZ is configurable with the volume_availability_zone option. If that doesn't solve things for you, we can reopen and continue to investigate.

wrath-m commented 4 years ago

Hi,

Thank you for the reply. @SwampDragons

Actually this doesn't change anything, as the image would still be somehow linked with a particular AZ. So with this variable defined, I'm still able to use the image only in the AZ which Packer uses to build the image. I'm pretty sure that "destination_type": "volume" from block_device_mapping is to blame (as Packer creates the volumes which are linked to the specified/default AZ), but I don't know how can I change that from Packer. From what I understand I'm in this case now: snapshot -> volume - this works exactly as passing type=snap does. It would create a volume from a Cinder volume snapshot and attach that volume to the instance. Can be marked bootable.

Best regards, Mihai

wrath-m commented 4 years ago

From Openstack documentation:

`Valid source / destination combinations¶ Combination of the source_type and destination_type will define the kind of block device the entry is referring to. The following combinations are supported:

image -> local - this is only currently reserved for the entry referring to the Glance image that the instance is being booted with (it should also be marked as a boot device). It is also worth noting that an API request that specifies this, also has to provide the same Glance uuid as the image_ref parameter to the boot request (this is done for backwards compatibility and may be changed in the future). This functionality might be extended to specify additional Glance images to be attached to an instance after boot (similar to kernel/ramdisk images) but this functionality is not supported by any of the current drivers. volume -> volume - this is just a Cinder volume to be attached to the instance. It can be marked as a boot device. snapshot -> volume - this works exactly as passing type=snap does. It would create a volume from a Cinder volume snapshot and attach that volume to the instance. Can be marked bootable. image -> volume - As one would imagine, this would download a Glance image to a cinder volume and attach it to an instance. Can also be marked as bootable. This is really only a shortcut for creating a volume out of an image before booting an instance with the newly created volume. blank -> volume - Creates a blank Cinder volume and attaches it. This will also require the volume size to be set. blank -> local - Depending on the guest_format field (see below), this will either mean an ephemeral blank disk on hypervisor local storage, or a swap disk (instances can have only one of those). `

In our case we have source_type: snapshot and destination_type: volume

wrath-m commented 4 years ago

I successfully built the image by converting from volume to image via cinder after the Packer build: cinder upload-to-image --disk-format vhd "name"

However I think there should be a way of having this output by using only Packer.