2013-05-09 17:16:39 -04:00
|
|
|
// The amazonebs package contains a packer.Builder implementation that
|
|
|
|
// builds AMIs for Amazon EC2.
|
|
|
|
//
|
|
|
|
// In general, there are two types of AMIs that can be created: ebs-backed or
|
|
|
|
// instance-store. This builder _only_ builds ebs-backed images.
|
2013-05-09 01:34:20 -04:00
|
|
|
package amazonebs
|
|
|
|
|
|
|
|
import (
|
2013-05-09 16:19:38 -04:00
|
|
|
"encoding/json"
|
2013-05-09 01:34:20 -04:00
|
|
|
"github.com/mitchellh/packer/packer"
|
2013-05-09 16:26:40 -04:00
|
|
|
"log"
|
2013-05-09 01:34:20 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type config struct {
|
2013-05-09 16:19:38 -04:00
|
|
|
AccessKey string `json:"access_key"`
|
2013-05-09 01:34:20 -04:00
|
|
|
Region string
|
2013-05-09 16:19:38 -04:00
|
|
|
SecretKey string `json:"secret_key"`
|
|
|
|
SourceAmi string `json:"source_ami"`
|
2013-05-09 01:34:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type Builder struct {
|
|
|
|
config config
|
|
|
|
}
|
|
|
|
|
2013-05-09 16:19:38 -04:00
|
|
|
func (b *Builder) Prepare(raw interface{}) (err error) {
|
2013-05-09 17:10:57 -04:00
|
|
|
// Marshal and unmarshal the raw configuration as a way to get it
|
|
|
|
// into our "config" struct.
|
|
|
|
// TODO: Use the reflection package and provide this as an API for
|
|
|
|
// better error messages
|
2013-05-09 16:19:38 -04:00
|
|
|
jsonBytes, err := json.Marshal(raw)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(jsonBytes, &b.config)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-05-09 16:26:40 -04:00
|
|
|
log.Printf("Config: %+v\n", b.config)
|
2013-05-10 16:01:54 -04:00
|
|
|
|
|
|
|
// TODO: Validate the configuration
|
2013-05-09 16:19:38 -04:00
|
|
|
return
|
2013-05-09 13:54:42 -04:00
|
|
|
}
|
2013-05-09 01:34:20 -04:00
|
|
|
|
2013-05-10 16:01:54 -04:00
|
|
|
func (*Builder) Run(b packer.Build, ui packer.Ui) {
|
|
|
|
ui.Say("Building an AWS image...\n")
|
|
|
|
}
|