From 952b2c921fc9d44f7a3da57f59972c212f9dd2ff Mon Sep 17 00:00:00 2001 From: James Massara Date: Wed, 4 Sep 2013 17:48:00 -0700 Subject: [PATCH] Also deregister AMI if it was copied to other regions --- builder/amazon/common/artifact.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builder/amazon/common/artifact.go b/builder/amazon/common/artifact.go index af6d1f2d4..3913833d7 100644 --- a/builder/amazon/common/artifact.go +++ b/builder/amazon/common/artifact.go @@ -2,6 +2,7 @@ package common import ( "fmt" + "github.com/mitchellh/goamz/aws" "github.com/mitchellh/goamz/ec2" "github.com/mitchellh/packer/packer" "log" @@ -51,9 +52,10 @@ func (a *Artifact) String() string { func (a *Artifact) Destroy() error { errors := make([]error, 0) - for _, imageId := range a.Amis { - log.Printf("Deregistering image ID: %s", imageId) - if _, err := a.Conn.DeregisterImage(imageId); err != nil { + for region, imageId := range a.Amis { + log.Printf("Deregistering image ID (%s) from region (%s)", imageId, region) + regionconn := ec2.New(a.Conn.Auth, aws.Regions[region]) + if _, err := regionconn.DeregisterImage(imageId); err != nil { errors = append(errors, err) }