OpenStack builder: Make external source image props configurable

Signed-off-by: Niels Pardon <par@zurich.ibm.com>
This commit is contained in:
Niels Pardon 2020-12-09 13:49:07 +00:00
parent 8eeeb91c90
commit 0e56b83196
5 changed files with 255 additions and 250 deletions

View File

@ -108,6 +108,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
SourceImageName: b.config.RunConfig.SourceImageName,
ExternalSourceImageURL: b.config.RunConfig.ExternalSourceImageURL,
ExternalSourceImageFormat: b.config.RunConfig.ExternalSourceImageFormat,
ExternalSourceImageProperties: b.config.RunConfig.ExternalSourceImageProperties,
SourceImageOpts: b.config.RunConfig.sourceImageOpts,
SourceMostRecent: b.config.SourceImageFilters.MostRecent,
SourceProperties: b.config.SourceImageFilters.Filters.Properties,

View File

@ -100,6 +100,7 @@ type FlatConfig struct {
SourceImageName *string `mapstructure:"source_image_name" required:"true" cty:"source_image_name" hcl:"source_image_name"`
ExternalSourceImageURL *string `mapstructure:"external_source_image_url" required:"true" cty:"external_source_image_url" hcl:"external_source_image_url"`
ExternalSourceImageFormat *string `mapstructure:"external_source_image_format" required:"false" cty:"external_source_image_format" hcl:"external_source_image_format"`
ExternalSourceImageProperties map[string]string `mapstructure:"external_source_image_properties" required:"false" cty:"external_source_image_properties" hcl:"external_source_image_properties"`
SourceImageFilters *FlatImageFilter `mapstructure:"source_image_filter" required:"true" cty:"source_image_filter" hcl:"source_image_filter"`
Flavor *string `mapstructure:"flavor" required:"true" cty:"flavor" hcl:"flavor"`
AvailabilityZone *string `mapstructure:"availability_zone" required:"false" cty:"availability_zone" hcl:"availability_zone"`
@ -230,6 +231,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"source_image_name": &hcldec.AttrSpec{Name: "source_image_name", Type: cty.String, Required: false},
"external_source_image_url": &hcldec.AttrSpec{Name: "external_source_image_url", Type: cty.String, Required: false},
"external_source_image_format": &hcldec.AttrSpec{Name: "external_source_image_format", Type: cty.String, Required: false},
"external_source_image_properties": &hcldec.AttrSpec{Name: "external_source_image_properties", Type: cty.Map(cty.String), Required: false},
"source_image_filter": &hcldec.BlockSpec{TypeName: "source_image_filter", Nested: hcldec.ObjectSpec((*FlatImageFilter)(nil).HCL2Spec())},
"flavor": &hcldec.AttrSpec{Name: "flavor", Type: cty.String, Required: false},
"availability_zone": &hcldec.AttrSpec{Name: "availability_zone", Type: cty.String, Required: false},

View File

@ -38,6 +38,8 @@ type RunConfig struct {
ExternalSourceImageURL string `mapstructure:"external_source_image_url" required:"true"`
// The format of the external source image to use, e.g. qcow2, raw.
ExternalSourceImageFormat string `mapstructure:"external_source_image_format" required:"false"`
// Properties to set for the external source image
ExternalSourceImageProperties map[string]string `mapstructure:"external_source_image_properties" required:"false"`
// Filters used to populate filter options. Example:
//
// ```json

View File

@ -18,6 +18,7 @@ type StepSourceImageInfo struct {
SourceImageName string
ExternalSourceImageURL string
ExternalSourceImageFormat string
ExternalSourceImageProperties map[string]string
SourceImageOpts images.ListOpts
SourceMostRecent bool
SourceProperties map[string]string
@ -50,10 +51,7 @@ func (s *StepSourceImageInfo) Run(ctx context.Context, state multistep.StateBag)
Name: s.SourceImageName,
ContainerFormat: "bare",
DiskFormat: s.ExternalSourceImageFormat,
Properties: map[string]string{
"packer_external_source_image_url": s.ExternalSourceImageURL,
"packer_external_source_image_format": s.ExternalSourceImageFormat,
},
Properties: s.ExternalSourceImageProperties,
}
ui.Say("Creating image using external source image with name " + s.SourceImageName)

View File

@ -11,6 +11,8 @@
- `external_source_image_format` (string) - The format of the external source image to use, e.g. qcow2, raw.
- `external_source_image_properties` (map[string]string) - Properties to set for the external source image
- `availability_zone` (string) - The availability zone to launch the server in. If this isn't specified,
the default enforced by your OpenStack cluster will be used. This may be
required for some OpenStack clusters.