builder/amazon/chroot: more settings, validation
This commit is contained in:
parent
cffb35ab33
commit
ec526d97aa
|
@ -24,7 +24,10 @@ type Config struct {
|
|||
common.PackerConfig `mapstructure:",squash"`
|
||||
awscommon.AccessConfig `mapstructure:",squash"`
|
||||
|
||||
SourceAmi string `mapstructure:"source_ami"`
|
||||
SourceAmi string `mapstructure:"source_ami"`
|
||||
AttachedDevicePath string `mapstructure:"attached_device_path"`
|
||||
DevicePath string `mapstructure:"device_path"`
|
||||
MountPath string `mapstructure:"mount_path"`
|
||||
}
|
||||
|
||||
type Builder struct {
|
||||
|
@ -39,11 +42,22 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|||
}
|
||||
|
||||
// Defaults
|
||||
if b.config.DevicePath == "" {
|
||||
b.config.DevicePath = "/dev/sdh"
|
||||
}
|
||||
|
||||
if b.config.MountPath == "" {
|
||||
b.config.MountPath = "/var/packer-amazon-chroot/volumes/{{.Device}}"
|
||||
}
|
||||
|
||||
// Accumulate any errors
|
||||
errs := common.CheckUnusedConfig(md)
|
||||
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare()...)
|
||||
|
||||
if b.config.SourceAmi == "" {
|
||||
errs = packer.MultiErrorAppend(errs, errors.New("source_ami is required."))
|
||||
}
|
||||
|
||||
if errs != nil && len(errs.Errors) > 0 {
|
||||
return errs
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ import (
|
|||
)
|
||||
|
||||
func testConfig() map[string]interface{} {
|
||||
return map[string]interface{}{}
|
||||
return map[string]interface{}{
|
||||
"source_ami": "foo",
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilder_ImplementsBuilder(t *testing.T) {
|
||||
|
@ -16,3 +18,20 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
|
|||
t.Fatalf("Builder should be a builder")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_SourceAmi(t *testing.T) {
|
||||
b := &Builder{}
|
||||
config := testConfig()
|
||||
|
||||
config["source_ami"] = ""
|
||||
err := b.Prepare(config)
|
||||
if err == nil {
|
||||
t.Fatal("should have error")
|
||||
}
|
||||
|
||||
config["source_ami"] = "foo"
|
||||
err = b.Prepare(config)
|
||||
if err != nil {
|
||||
t.Errorf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,13 @@ type StepAttachVolume struct {
|
|||
}
|
||||
|
||||
func (s *StepAttachVolume) Run(state map[string]interface{}) multistep.StepAction {
|
||||
config := state["config"].(*Config)
|
||||
ec2conn := state["ec2"].(*ec2.EC2)
|
||||
instance := state["instance"].(*ec2.Instance)
|
||||
ui := state["ui"].(packer.Ui)
|
||||
volumeId := state["volume_id"].(string)
|
||||
|
||||
device := "/dev/sdh"
|
||||
device := config.DevicePath
|
||||
|
||||
ui.Say("Attaching the root volume...")
|
||||
_, err := ec2conn.AttachVolume(volumeId, instance.InstanceId, device)
|
||||
|
|
Loading…
Reference in New Issue