From 1eec5bf0584051b6d0e7dc6a31030573f7e86768 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Mon, 27 Feb 2017 00:40:07 -0600 Subject: [PATCH] builder/amazon-ebssurrogate: Exclude duplicate root volume This commit removes the root volume from the list of launch block device mappings passed to the image, since it is already passed in the form of a snapshot (which is then configured to be the root device). Without this commit, AMIs created using this builder have two root volumes attached on launch. --- builder/amazon/ebssurrogate/step_register_ami.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/builder/amazon/ebssurrogate/step_register_ami.go b/builder/amazon/ebssurrogate/step_register_ami.go index 975854b96..c4d8d9480 100644 --- a/builder/amazon/ebssurrogate/step_register_ami.go +++ b/builder/amazon/ebssurrogate/step_register_ami.go @@ -24,15 +24,23 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction { ui.Say("Registering the AMI...") - blockDevices := s.BlockDevices - blockDevices = append(blockDevices, s.RootDevice.createBlockDeviceMapping(snapshotId)) + blockDevicesExcludingRoot := make([]*ec2.BlockDeviceMapping, 0, len(s.BlockDevices)-1) + for _, blockDevice := range s.BlockDevices { + if *blockDevice.DeviceName == s.RootDevice.SourceDeviceName { + continue + } + + blockDevicesExcludingRoot = append(blockDevicesExcludingRoot, blockDevice) + } + + blockDevicesExcludingRoot = append(blockDevicesExcludingRoot, s.RootDevice.createBlockDeviceMapping(snapshotId)) registerOpts := &ec2.RegisterImageInput{ Name: &config.AMIName, Architecture: aws.String(ec2.ArchitectureValuesX8664), RootDeviceName: aws.String(s.RootDevice.DeviceName), VirtualizationType: aws.String(config.AMIVirtType), - BlockDeviceMappings: blockDevices, + BlockDeviceMappings: blockDevicesExcludingRoot, } if config.AMIEnhancedNetworking {