Commit 5da56d2a authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/digitalocean: image, region, etc. required

parent be8443d5
......@@ -14,18 +14,6 @@ import (
"golang.org/x/oauth2"
)
// see https://api.digitalocean.com/images/?client_id=[client_id]&api_key=[api_key]
// name="Ubuntu 12.04.4 x64", id=6374128,
const DefaultImage = "ubuntu-12-04-x64"
// see https://api.digitalocean.com/regions/?client_id=[client_id]&api_key=[api_key]
// name="New York 3", id=8
const DefaultRegion = "nyc3"
// see https://api.digitalocean.com/sizes/?client_id=[client_id]&api_key=[api_key]
// name="512MB", id=66 (the smallest droplet size)
const DefaultSize = "512mb"
// The unique id for the builder
const BuilderId = "pearkes.digitalocean"
......
......@@ -24,7 +24,10 @@ func testAccPreCheck(t *testing.T) {
const testBuilderAccBasic = `
{
"builders": [{
"type": "test"
"type": "test",
"region": "nyc2",
"size": "512mb",
"image": "ubuntu-12-04-x64"
}]
}
`
......@@ -60,12 +60,8 @@ func TestBuilderPrepare_Region(t *testing.T) {
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}
if b.config.Region != DefaultRegion {
t.Errorf("found %s, expected %s", b.config.Region, DefaultRegion)
if err == nil {
t.Fatalf("should error")
}
expected := "sfo1"
......@@ -95,12 +91,8 @@ func TestBuilderPrepare_Size(t *testing.T) {
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}
if b.config.Size != DefaultSize {
t.Errorf("found %s, expected %s", b.config.Size, DefaultSize)
if err == nil {
t.Fatalf("should error")
}
expected := "1024mb"
......@@ -130,12 +122,8 @@ func TestBuilderPrepare_Image(t *testing.T) {
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}
if b.config.Image != DefaultImage {
t.Errorf("found %s, expected %s", b.config.Image, DefaultImage)
if err == nil {
t.Fatal("should error")
}
expected := "ubuntu-14-04-x64"
......
......@@ -63,18 +63,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
c.APIToken = os.Getenv("DIGITALOCEAN_API_TOKEN")
}
if c.Region == "" {
c.Region = DefaultRegion
}
if c.Size == "" {
c.Size = DefaultSize
}
if c.Image == "" {
c.Image = DefaultImage
}
if c.SnapshotName == "" {
// Default to packer-{{ unix timestamp (utc) }}
c.SnapshotName = "packer-{{timestamp}}"
......@@ -114,6 +102,21 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs, errors.New("api_token for auth must be specified"))
}
if c.Region == "" {
errs = packer.MultiErrorAppend(
errs, errors.New("region is required"))
}
if c.Size == "" {
errs = packer.MultiErrorAppend(
errs, errors.New("size is required"))
}
if c.Image == "" {
errs = packer.MultiErrorAppend(
errs, errors.New("image is required"))
}
sshTimeout, err := time.ParseDuration(c.RawSSHTimeout)
if err != nil {
errs = packer.MultiErrorAppend(
......
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