builder/amazonebs: Validate region exists
This commit is contained in:
parent
4fa27e6a30
commit
be1e60aa26
|
@ -7,6 +7,7 @@ package amazonebs
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/mitchellh/goamz/aws"
|
||||
"github.com/mitchellh/goamz/ec2"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
@ -70,6 +71,8 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
|
|||
|
||||
if b.config.Region == "" {
|
||||
errs = append(errs, errors.New("A region must be specified"))
|
||||
} else if _, ok := aws.Regions[b.config.Region]; !ok {
|
||||
errs = append(errs, fmt.Errorf("Unknown region: %s", b.config.Region))
|
||||
}
|
||||
|
||||
if b.config.SSHUsername == "" {
|
||||
|
|
|
@ -11,7 +11,7 @@ func testConfig() map[string]interface{} {
|
|||
"secret_key": "bar",
|
||||
"source_ami": "foo",
|
||||
"instance_type": "foo",
|
||||
"region": "foo",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "root",
|
||||
}
|
||||
}
|
||||
|
@ -89,13 +89,13 @@ func TestBuilderPrepare_Region(t *testing.T) {
|
|||
config := testConfig()
|
||||
|
||||
// Test good
|
||||
config["region"] = "foo"
|
||||
config["region"] = "us-east-1"
|
||||
err := b.Prepare(config)
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
if b.config.Region != "foo" {
|
||||
if b.config.Region != "us-east-1" {
|
||||
t.Errorf("invalid: %s", b.config.Region)
|
||||
}
|
||||
|
||||
|
@ -106,6 +106,14 @@ func TestBuilderPrepare_Region(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Fatal("should have error")
|
||||
}
|
||||
|
||||
// Test invalid
|
||||
config["region"] = "i-am-not-real"
|
||||
b = Builder{}
|
||||
err = b.Prepare(config)
|
||||
if err == nil {
|
||||
t.Fatal("should have error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_SecretKey(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue