diff --git a/builder/amazon/ebs/artifact.go b/builder/amazon/common/artifact.go similarity index 54% rename from builder/amazon/ebs/artifact.go rename to builder/amazon/common/artifact.go index 4d25d4595..af6d1f2d4 100644 --- a/builder/amazon/ebs/artifact.go +++ b/builder/amazon/common/artifact.go @@ -1,4 +1,4 @@ -package ebs +package common import ( "fmt" @@ -8,35 +8,39 @@ import ( "strings" ) -type artifact struct { +// Artifact is an artifact implementation that contains built AMIs. +type Artifact struct { // A map of regions to AMI IDs. - amis map[string]string + Amis map[string]string + + // BuilderId is the unique ID for the builder that created this AMI + BuilderIdValue string // EC2 connection for performing API stuff. - conn *ec2.EC2 + Conn *ec2.EC2 } -func (*artifact) BuilderId() string { - return BuilderId +func (a *Artifact) BuilderId() string { + return a.BuilderIdValue } -func (*artifact) Files() []string { +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 { +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 { +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) } @@ -44,12 +48,12 @@ func (a *artifact) String() string { return fmt.Sprintf("AMIs were created:\n\n%s", strings.Join(amiStrings, "\n")) } -func (a *artifact) Destroy() error { +func (a *Artifact) Destroy() error { errors := make([]error, 0) - for _, imageId := range a.amis { + for _, imageId := range a.Amis { log.Printf("Deregistering image ID: %s", imageId) - if _, err := a.conn.DeregisterImage(imageId); err != nil { + if _, err := a.Conn.DeregisterImage(imageId); err != nil { errors = append(errors, err) } diff --git a/builder/amazon/ebs/artifact_test.go b/builder/amazon/common/artifact_test.go similarity index 85% rename from builder/amazon/ebs/artifact_test.go rename to builder/amazon/common/artifact_test.go index dd8ccba9b..be8121074 100644 --- a/builder/amazon/ebs/artifact_test.go +++ b/builder/amazon/common/artifact_test.go @@ -1,4 +1,4 @@ -package ebs +package common import ( "cgl.tideland.biz/asserts" @@ -10,7 +10,7 @@ func TestArtifact_Impl(t *testing.T) { assert := asserts.NewTestingAsserts(t, true) var actual packer.Artifact - assert.Implementor(&artifact{}, &actual, "should be an Artifact") + assert.Implementor(&Artifact{}, &actual, "should be an Artifact") } func TestArtifactId(t *testing.T) { @@ -22,7 +22,7 @@ func TestArtifactId(t *testing.T) { amis["east"] = "foo" amis["west"] = "bar" - a := &artifact{amis, nil} + a := &Artifact{amis, nil} result := a.Id() assert.Equal(result, expected, "should match output") } @@ -39,7 +39,7 @@ west: bar` amis["east"] = "foo" amis["west"] = "bar" - a := &artifact{amis, nil} + a := &Artifact{amis, nil} result := a.String() assert.Equal(result, expected, "should match output") } diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index 48658f636..da11e68b9 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -131,9 +131,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe } // Build the artifact and return it - artifact := &artifact{ - amis: state["amis"].(map[string]string), - conn: ec2conn, + artifact := &awscommon.Artifact{ + Amis: state["amis"].(map[string]string), + BuilderIdValue: BuilderId, + Conn: ec2conn, } return artifact, nil