Commit a587bd47 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/amazon/ebs: clean up AMI in error [GH-1186]

parent 669f26a1
......@@ -63,6 +63,7 @@ BUG FIXES:
* builder/amazon-chroot: Fix crash in root device check. [GH-1360]
* builder/amazon-chroot: Add description that Packer made the snapshot
with a time. [GH-1388]
* builder/amazon-ebs: AMI is deregistered if an error. [GH-1186]
* builder/amazon-instance: Fix deprecation warning for `ec2-bundle-vol`
[GH-1424]
* builder/amazon-instance: Add `--no-filter` to the `ec2-bundle-vol`
......
......@@ -69,14 +69,17 @@ func (s *stepCreateAMI) Run(state multistep.StateBag) multistep.StepAction {
}
func (s *stepCreateAMI) Cleanup(state multistep.StateBag) {
if s.image == nil || s.image.State == "available" {
_, cancelled := state.GetOk(multistep.StateCancelled)
_, halted := state.GetOk(multistep.StateHalted)
if !cancelled && !halted {
return
}
ec2conn := state.Get("ec2").(*ec2.EC2)
ui := state.Get("ui").(packer.Ui)
ui.Say("Deregistering the AMI ...")
ui.Say("Deregistering the AMI because cancelation or error...")
if resp, err := ec2conn.DeregisterImage(s.image.Id); err != nil {
ui.Error(fmt.Sprintf("Error deregistering AMI, may still be around: %s", err))
return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment