diff --git a/builder/amazonebs/artifact.go b/builder/amazonebs/artifact.go new file mode 100644 index 000000000..9041f928f --- /dev/null +++ b/builder/amazonebs/artifact.go @@ -0,0 +1,35 @@ +package amazonebs + +import ( + "fmt" + "strings" +) + +type artifact struct{ + // A map of regions to AMI IDs. + amis map[string]string +} + +func (*artifact) BuilderId() string { + return BuilderId +} + +func (*artifact) Files() []string { + // We have no files + return nil +} + +func (*artifact) Id() string { + // TODO(mitchellh): Id + return "TODO" +} + +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")) +} diff --git a/builder/amazonebs/artifact_test.go b/builder/amazonebs/artifact_test.go new file mode 100644 index 000000000..992e19aea --- /dev/null +++ b/builder/amazonebs/artifact_test.go @@ -0,0 +1,31 @@ +package amazonebs + +import ( + "cgl.tideland.biz/asserts" + "github.com/mitchellh/packer/packer" + "testing" +) + +func TestArtifact_Impl(t *testing.T) { + assert := asserts.NewTestingAsserts(t, true) + + var actual packer.Artifact + assert.Implementor(&artifact{}, &actual, "should be an Artifact") +} + +func TestArtifactString(t *testing.T) { + assert := asserts.NewTestingAsserts(t, true) + + expected := `AMIs were created: + +east: foo +west: bar` + + amis := make(map[string]string) + amis["east"] = "foo" + amis["west"] = "bar" + + a := &artifact{amis} + result := a.String() + assert.Equal(result, expected, "should match output") +} diff --git a/builder/amazonebs/builder.go b/builder/amazonebs/builder.go index ddfb5d628..0af6a84ad 100644 --- a/builder/amazonebs/builder.go +++ b/builder/amazonebs/builder.go @@ -13,6 +13,9 @@ import ( "log" ) +// The unique ID for this builder +const BuilderId = "mitchellh.amazonebs" + type config struct { // Access information AccessKey string `mapstructure:"access_key"` @@ -45,7 +48,7 @@ func (b *Builder) Prepare(raw interface{}) (err error) { return } -func (b *Builder) Run(ui packer.Ui, hook packer.Hook) { +func (b *Builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact { auth := aws.Auth{b.config.AccessKey, b.config.SecretKey} region := aws.Regions[b.config.Region] ec2conn := ec2.New(auth, region) @@ -67,4 +70,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) { // Run! RunSteps(state, steps) + + // Build the artifact and return it + return &artifact{state["amis"].(map[string]string)} } diff --git a/builder/amazonebs/step_create_ami.go b/builder/amazonebs/step_create_ami.go index 7838335f0..e0a187911 100644 --- a/builder/amazonebs/step_create_ami.go +++ b/builder/amazonebs/step_create_ami.go @@ -26,7 +26,11 @@ func (s *stepCreateAMI) Run(state map[string]interface{}) StepAction { return StepHalt } + // Set the AMI ID in the state ui.Say("AMI: %s", createResp.ImageId) + amis := make(map[string]string) + amis[config.Region] = createResp.ImageId + state["amis"] = amis // Wait for the image to become ready ui.Say("Waiting for AMI to become ready...")