Commit 2dfc5d3e authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/amazon: inject special metadata for atlas artifacts

parent 73c5192b
...@@ -2,12 +2,13 @@ package common ...@@ -2,12 +2,13 @@ package common
import ( import (
"fmt" "fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/packer/packer"
"log" "log"
"sort" "sort"
"strings" "strings"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/packer/packer"
) )
// Artifact is an artifact implementation that contains built AMIs. // Artifact is an artifact implementation that contains built AMIs.
...@@ -53,7 +54,12 @@ func (a *Artifact) String() string { ...@@ -53,7 +54,12 @@ func (a *Artifact) String() string {
} }
func (a *Artifact) State(name string) interface{} { func (a *Artifact) State(name string) interface{} {
return nil switch name {
case "atlas.artifact.metadata":
return a.stateAtlasMetadata()
default:
return nil
}
} }
func (a *Artifact) Destroy() error { func (a *Artifact) Destroy() error {
...@@ -79,3 +85,13 @@ func (a *Artifact) Destroy() error { ...@@ -79,3 +85,13 @@ func (a *Artifact) Destroy() error {
return nil return nil
} }
func (a *Artifact) stateAtlasMetadata() interface{} {
metadata := make(map[string]string)
for region, imageId := range a.Amis {
k := fmt.Sprintf("region.%s", region)
metadata[k] = imageId
}
return metadata
}
package common package common
import ( import (
"github.com/mitchellh/packer/packer" "reflect"
"testing" "testing"
"github.com/mitchellh/packer/packer"
) )
func TestArtifact_Impl(t *testing.T) { func TestArtifact_Impl(t *testing.T) {
...@@ -26,6 +28,24 @@ func TestArtifactId(t *testing.T) { ...@@ -26,6 +28,24 @@ func TestArtifactId(t *testing.T) {
} }
} }
func TestArtifactState_atlasMetadata(t *testing.T) {
a := &Artifact{
Amis: map[string]string{
"east": "foo",
"west": "bar",
},
}
actual := a.State("atlas.artifact.metadata")
expected := map[string]string{
"region.east": "foo",
"region.west": "bar",
}
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}
func TestArtifactString(t *testing.T) { func TestArtifactString(t *testing.T) {
expected := `AMIs were created: expected := `AMIs were created:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment