Merge pull request #7218 from Adezandee/gce-import

googlecompute-import: add guest os features
This commit is contained in:
Adrien Delorme 2019-01-23 16:25:21 +01:00 committed by GitHub
commit 4cc4784563
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 18 deletions

View File

@ -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))

View File

@ -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.