Merge pull request #4930 from hashicorp/fix4925

builder/amazon: don't try to delete extra volumes during clean up
This commit is contained in:
Matthew Hooker 2017-06-02 14:08:49 -07:00 committed by GitHub
commit 11ba986abc
1 changed files with 5 additions and 18 deletions

View File

@ -37,22 +37,8 @@ func (s *stepCleanupVolumes) Cleanup(state multistep.StateBag) {
ui.Say("Cleaning up any extra volumes...")
// We don't actually care about the value here, but we need Set behavior
save := make(map[string]struct{})
for _, b := range s.BlockDevices.AMIMappings {
if !b.DeleteOnTermination {
save[b.DeviceName] = struct{}{}
}
}
for _, b := range s.BlockDevices.LaunchMappings {
if !b.DeleteOnTermination {
save[b.DeviceName] = struct{}{}
}
}
// Collect Volume information from the cached Instance as a map of volume-id
// to device name, to compare with save list above
// to device name, to compare with save list below
var vl []*string
volList := make(map[string]string)
for _, bdm := range instance.BlockDeviceMappings {
@ -91,10 +77,11 @@ func (s *stepCleanupVolumes) Cleanup(state multistep.StateBag) {
return
}
// Filter out any devices marked for saving
for saveName := range save {
// Filter out any devices created as part of the launch mappings, since
// we'll let amazon follow the `delete_on_termination` setting.
for _, b := range s.BlockDevices.LaunchMappings {
for volKey, volName := range volList {
if volName == saveName {
if volName == b.DeviceName {
delete(volList, volKey)
}
}