packer-cn/builder/amazonebs/builder.go

49 lines
1.1 KiB
Go
Raw Normal View History

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.
package amazonebs
import (
2013-05-09 16:19:38 -04:00
"encoding/json"
"github.com/mitchellh/packer/packer"
2013-05-09 16:26:40 -04:00
"log"
)
type config struct {
2013-05-09 16:19:38 -04:00
AccessKey string `json:"access_key"`
Region string
2013-05-09 16:19:38 -04:00
SecretKey string `json:"secret_key"`
SourceAmi string `json:"source_ami"`
}
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)
// TODO: Validate the configuration
2013-05-09 16:19:38 -04:00
return
}
func (*Builder) Run(b packer.Build, ui packer.Ui) {
ui.Say("Building an AWS image...\n")
}