diff --git a/builder/openstack/builder.go b/builder/openstack/builder.go index 7aba1d432..441636ae2 100644 --- a/builder/openstack/builder.go +++ b/builder/openstack/builder.go @@ -52,6 +52,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { return nil, errs } + if b.config.ImageConfig.ImageDiskFormat != "" && !b.config.RunConfig.UseBlockStorageVolume { + return nil, fmt.Errorf("use_blockstorage_volume must be true if image_disk_format is specified.") + } + // By default, instance name is same as image name if b.config.InstanceName == "" { b.config.InstanceName = b.config.ImageName diff --git a/builder/openstack/image_config.go b/builder/openstack/image_config.go index 3bdc1fc50..f17ad753d 100644 --- a/builder/openstack/image_config.go +++ b/builder/openstack/image_config.go @@ -14,6 +14,7 @@ type ImageConfig struct { ImageMetadata map[string]string `mapstructure:"metadata"` ImageVisibility imageservice.ImageVisibility `mapstructure:"image_visibility"` ImageMembers []string `mapstructure:"image_members"` + ImageDiskFormat string `mapstructure:"image_disk_format"` } func (c *ImageConfig) Prepare(ctx *interpolate.Context) []error { diff --git a/builder/openstack/step_create_image.go b/builder/openstack/step_create_image.go index 550ddcd28..260596ffb 100644 --- a/builder/openstack/step_create_image.go +++ b/builder/openstack/step_create_image.go @@ -47,7 +47,8 @@ func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multi } volume := state.Get("volume_id").(string) image, err := volumeactions.UploadImage(blockStorageClient, volume, volumeactions.UploadImageOpts{ - ImageName: config.ImageName, + DiskFormat: config.ImageDiskFormat, + ImageName: config.ImageName, }).Extract() if err != nil { err := fmt.Errorf("Error creating image: %s", err) diff --git a/website/source/docs/builders/openstack.html.md b/website/source/docs/builders/openstack.html.md index 28566bd0d..ab75b1071 100644 --- a/website/source/docs/builders/openstack.html.md +++ b/website/source/docs/builders/openstack.html.md @@ -275,6 +275,9 @@ builder. zones aren't specified, the default enforced by your OpenStack cluster will be used. +- `image_disk_format` (string) - Disk format of the resulting image. + This option works if `use_blockstorage_volume` is true. + ## Basic Example: DevStack Here is a basic example. This is a example to build on DevStack running in a VM.