From f374edc2b8ffdd001754117a9c44654dc0af4f6f Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Mon, 22 Jun 2015 17:08:41 -0500 Subject: [PATCH] builder/amazon-chroot: Fixes for amazon-chroot builder These are needed for chroot builder to work --- builder/amazon/chroot/step_create_volume.go | 2 +- builder/amazon/chroot/step_instance_info.go | 2 +- builder/amazon/chroot/step_register_ami.go | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/builder/amazon/chroot/step_create_volume.go b/builder/amazon/chroot/step_create_volume.go index 2d7205e8d..81486f5e2 100644 --- a/builder/amazon/chroot/step_create_volume.go +++ b/builder/amazon/chroot/step_create_volume.go @@ -29,7 +29,7 @@ func (s *StepCreateVolume) Run(state multistep.StateBag) multistep.StepAction { log.Printf("Searching for root device of the image (%s)", *image.RootDeviceName) var rootDevice *ec2.BlockDeviceMapping for _, device := range image.BlockDeviceMappings { - if device.DeviceName == image.RootDeviceName { + if *device.DeviceName == *image.RootDeviceName { rootDevice = device break } diff --git a/builder/amazon/chroot/step_instance_info.go b/builder/amazon/chroot/step_instance_info.go index ee8dbb3e6..b77c9e8a1 100644 --- a/builder/amazon/chroot/step_instance_info.go +++ b/builder/amazon/chroot/step_instance_info.go @@ -49,7 +49,7 @@ func (s *StepInstanceInfo) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } - instance := &instancesResp.Reservations[0].Instances[0] + instance := instancesResp.Reservations[0].Instances[0] state.Put("instance", instance) return multistep.ActionContinue diff --git a/builder/amazon/chroot/step_register_ami.go b/builder/amazon/chroot/step_register_ami.go index ee2cf48e4..1d61068cf 100644 --- a/builder/amazon/chroot/step_register_ami.go +++ b/builder/amazon/chroot/step_register_ami.go @@ -24,14 +24,20 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction { blockDevices := make([]*ec2.BlockDeviceMapping, len(image.BlockDeviceMappings)) for i, device := range image.BlockDeviceMappings { newDevice := device - if newDevice.DeviceName == image.RootDeviceName { + if *newDevice.DeviceName == *image.RootDeviceName { if newDevice.EBS != nil { - newDevice.EBS.SnapshotID = &snapshotId + newDevice.EBS.SnapshotID = aws.String(snapshotId) } else { - newDevice.EBS = &ec2.EBSBlockDevice{SnapshotID: &snapshotId} + newDevice.EBS = &ec2.EBSBlockDevice{SnapshotID: aws.String(snapshotId)} } } + // assume working from a snapshot, so we unset the Encrypted field if set, + // otherwise AWS API will return InvalidParameter + if newDevice.EBS.Encrypted != nil { + newDevice.EBS.Encrypted = nil + } + blockDevices[i] = newDevice } @@ -82,7 +88,10 @@ func buildRegisterOpts(config *Config, image *ec2.Image, blockDevices []*ec2.Blo Architecture: image.Architecture, RootDeviceName: image.RootDeviceName, BlockDeviceMappings: blockDevices, - VirtualizationType: &config.AMIVirtType, + } + + if config.AMIVirtType != "" { + registerOpts.VirtualizationType = aws.String(config.AMIVirtType) } if config.AMIVirtType != "hvm" {