builder/amazonebs: Artifact returns AMIs
This commit is contained in:
parent
e9618b0d07
commit
cf6d2218ea
|
@ -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"))
|
||||
}
|
|
@ -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")
|
||||
}
|
|
@ -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)}
|
||||
}
|
||||
|
|
|
@ -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...")
|
||||
|
|
Loading…
Reference in New Issue