Commit 4fa27e6a authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/amazonebs: Finish basic validation

parent 4223e5bc
...@@ -68,6 +68,10 @@ func (b *Builder) Prepare(raw interface{}) (err error) { ...@@ -68,6 +68,10 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
errs = append(errs, errors.New("An instance_type must be specified")) errs = append(errs, errors.New("An instance_type must be specified"))
} }
if b.config.Region == "" {
errs = append(errs, errors.New("A region must be specified"))
}
if b.config.SSHUsername == "" { if b.config.SSHUsername == "" {
errs = append(errs, errors.New("An ssh_username must be specified")) errs = append(errs, errors.New("An ssh_username must be specified"))
} }
...@@ -76,9 +80,6 @@ func (b *Builder) Prepare(raw interface{}) (err error) { ...@@ -76,9 +80,6 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
return &packer.MultiError{errs} return &packer.MultiError{errs}
} }
// TODO: config validation and asking for fields:
// * region (exists and valid)
log.Printf("Config: %+v", b.config) log.Printf("Config: %+v", b.config)
return return
} }
......
...@@ -11,6 +11,7 @@ func testConfig() map[string]interface{} { ...@@ -11,6 +11,7 @@ func testConfig() map[string]interface{} {
"secret_key": "bar", "secret_key": "bar",
"source_ami": "foo", "source_ami": "foo",
"instance_type": "foo", "instance_type": "foo",
"region": "foo",
"ssh_username": "root", "ssh_username": "root",
} }
} }
...@@ -83,6 +84,30 @@ func TestBuilderPrepare_InstanceType(t *testing.T) { ...@@ -83,6 +84,30 @@ func TestBuilderPrepare_InstanceType(t *testing.T) {
} }
} }
func TestBuilderPrepare_Region(t *testing.T) {
var b Builder
config := testConfig()
// Test good
config["region"] = "foo"
err := b.Prepare(config)
if err != nil {
t.Fatalf("should not have error: %s", err)
}
if b.config.Region != "foo" {
t.Errorf("invalid: %s", b.config.Region)
}
// Test bad
delete(config, "region")
b = Builder{}
err = b.Prepare(config)
if err == nil {
t.Fatal("should have error")
}
}
func TestBuilderPrepare_SecretKey(t *testing.T) { func TestBuilderPrepare_SecretKey(t *testing.T) {
var b Builder var b Builder
config := testConfig() config := testConfig()
......
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