From 3d41cdfacba6b4536136369a8d5c2f6f2a47db70 Mon Sep 17 00:00:00 2001 From: Arnaud Dezandee Date: Tue, 22 Jan 2019 00:09:29 +0100 Subject: [PATCH] googlecompute-import: add guest os features --- .../googlecompute-import/post-processor.go | 47 ++++++++++++------- .../googlecompute-import.html.md | 5 ++ 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/post-processor/googlecompute-import/post-processor.go b/post-processor/googlecompute-import/post-processor.go index 3e773cbda..6f44b1ce9 100644 --- a/post-processor/googlecompute-import/post-processor.go +++ b/post-processor/googlecompute-import/post-processor.go @@ -25,16 +25,18 @@ import ( type Config struct { common.PackerConfig `mapstructure:",squash"` - Bucket string `mapstructure:"bucket"` - GCSObjectName string `mapstructure:"gcs_object_name"` - ImageDescription string `mapstructure:"image_description"` - ImageFamily string `mapstructure:"image_family"` - ImageLabels map[string]string `mapstructure:"image_labels"` - ImageName string `mapstructure:"image_name"` - ProjectId string `mapstructure:"project_id"` - AccountFile string `mapstructure:"account_file"` - KeepOriginalImage bool `mapstructure:"keep_input_artifact"` - SkipClean bool `mapstructure:"skip_clean"` + AccountFile string `mapstructure:"account_file"` + ProjectId string `mapstructure:"project_id"` + + Bucket string `mapstructure:"bucket"` + GCSObjectName string `mapstructure:"gcs_object_name"` + ImageDescription string `mapstructure:"image_description"` + ImageFamily string `mapstructure:"image_family"` + ImageGuestOsFeatures []string `mapstructure:"image_guest_os_features"` + ImageLabels map[string]string `mapstructure:"image_labels"` + ImageName string `mapstructure:"image_name"` + KeepOriginalImage bool `mapstructure:"keep_input_artifact"` + SkipClean bool `mapstructure:"skip_clean"` ctx interpolate.Context } @@ -111,7 +113,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac return nil, p.config.KeepOriginalImage, err } - gceImageArtifact, err := CreateGceImage(p.config.AccountFile, ui, p.config.ProjectId, rawImageGcsPath, p.config.ImageName, p.config.ImageDescription, p.config.ImageFamily, p.config.ImageLabels) + gceImageArtifact, err := CreateGceImage(p.config.AccountFile, ui, p.config.ProjectId, rawImageGcsPath, p.config.ImageName, p.config.ImageDescription, p.config.ImageFamily, p.config.ImageLabels, p.config.ImageGuestOsFeatures) if err != nil { return nil, p.config.KeepOriginalImage, err } @@ -179,7 +181,7 @@ func UploadToBucket(accountFile string, ui packer.Ui, artifact packer.Artifact, return "https://storage.googleapis.com/" + bucket + "/" + gcsObjectName, nil } -func CreateGceImage(accountFile string, ui packer.Ui, project string, rawImageURL string, imageName string, imageDescription string, imageFamily string, imageLabels map[string]string) (packer.Artifact, error) { +func CreateGceImage(accountFile string, ui packer.Ui, project string, rawImageURL string, imageName string, imageDescription string, imageFamily string, imageLabels map[string]string, imageGuestOsFeatures []string) (packer.Artifact, error) { var client *http.Client var account googlecompute.AccountFile @@ -203,13 +205,22 @@ func CreateGceImage(accountFile string, ui packer.Ui, project string, rawImageUR return nil, err } + // Build up the imageFeatures + imageFeatures := make([]*compute.GuestOsFeature, len(imageGuestOsFeatures)) + for _, v := range imageGuestOsFeatures { + imageFeatures = append(imageFeatures, &compute.GuestOsFeature{ + Type: v, + }) + } + gceImage := &compute.Image{ - Name: imageName, - Description: imageDescription, - Family: imageFamily, - Labels: imageLabels, - RawDisk: &compute.ImageRawDisk{Source: rawImageURL}, - SourceType: "RAW", + Description: imageDescription, + Family: imageFamily, + GuestOsFeatures: imageFeatures, + Labels: imageLabels, + Name: imageName, + RawDisk: &compute.ImageRawDisk{Source: rawImageURL}, + SourceType: "RAW", } ui.Say(fmt.Sprintf("Creating GCE image %v...", imageName)) diff --git a/website/source/docs/post-processors/googlecompute-import.html.md b/website/source/docs/post-processors/googlecompute-import.html.md index 401d886b5..4676dfd3c 100644 --- a/website/source/docs/post-processors/googlecompute-import.html.md +++ b/website/source/docs/post-processors/googlecompute-import.html.md @@ -61,6 +61,11 @@ for details. - `image_labels` (object of key/value strings) - Key/value pair labels to apply to the created image. +- `image_guest_os_features` (array of strings) - A list of features to enable + on the guest operating system. Applicable only for bootable images. Valid + values are `MULTI_IP_SUBNET`, `SECURE_BOOT`, `UEFI_COMPATIBLE`, + `VIRTIO_SCSI_MULTIQUEUE` and `WINDOWS` currently. + - `keep_input_artifact` (boolean) - if true, do not delete the compressed RAW disk image. Defaults to false.