forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artifact.go
68 lines (54 loc) · 1.33 KB
/
artifact.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package amazonebs
import (
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/packer/packer"
"log"
"strings"
)
type artifact struct {
// A map of regions to AMI IDs.
amis map[string]string
// EC2 connection for performing API stuff.
conn *ec2.EC2
}
func (*artifact) BuilderId() string {
return BuilderId
}
func (*artifact) Files() []string {
// We have no files
return nil
}
func (a *artifact) Id() string {
parts := make([]string, 0, len(a.amis))
for region, amiId := range a.amis {
parts = append(parts, fmt.Sprintf("%s:%s", region, amiId))
}
return strings.Join(parts, ",")
}
func (a *artifact) String() string {
amiStrings := make([]string, 0, len(a.amis))
for region, id := range a.amis {
single := fmt.Sprintf("%s: %s", region, id)
amiStrings = append(amiStrings, single)
}
return fmt.Sprintf("AMIs were created:\n\n%s", strings.Join(amiStrings, "\n"))
}
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 {
errors = append(errors, err)
}
// TODO(mitchellh): Delete the snapshots associated with an AMI too
}
if len(errors) > 0 {
if len(errors) == 1 {
return errors[0]
} else {
return &packer.MultiError{errors}
}
}
return nil
}