builder/digitalocean: image, region, etc. required
This commit is contained in:
parent
be8443d508
commit
5da56d2aa6
|
@ -14,18 +14,6 @@ import (
|
||||||
"golang.org/x/oauth2"
|
"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
|
// The unique id for the builder
|
||||||
const BuilderId = "pearkes.digitalocean"
|
const BuilderId = "pearkes.digitalocean"
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,10 @@ func testAccPreCheck(t *testing.T) {
|
||||||
const testBuilderAccBasic = `
|
const testBuilderAccBasic = `
|
||||||
{
|
{
|
||||||
"builders": [{
|
"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 {
|
if len(warnings) > 0 {
|
||||||
t.Fatalf("bad: %#v", warnings)
|
t.Fatalf("bad: %#v", warnings)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err == nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should error")
|
||||||
}
|
|
||||||
|
|
||||||
if b.config.Region != DefaultRegion {
|
|
||||||
t.Errorf("found %s, expected %s", b.config.Region, DefaultRegion)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := "sfo1"
|
expected := "sfo1"
|
||||||
|
@ -95,12 +91,8 @@ func TestBuilderPrepare_Size(t *testing.T) {
|
||||||
if len(warnings) > 0 {
|
if len(warnings) > 0 {
|
||||||
t.Fatalf("bad: %#v", warnings)
|
t.Fatalf("bad: %#v", warnings)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err == nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should error")
|
||||||
}
|
|
||||||
|
|
||||||
if b.config.Size != DefaultSize {
|
|
||||||
t.Errorf("found %s, expected %s", b.config.Size, DefaultSize)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := "1024mb"
|
expected := "1024mb"
|
||||||
|
@ -130,12 +122,8 @@ func TestBuilderPrepare_Image(t *testing.T) {
|
||||||
if len(warnings) > 0 {
|
if len(warnings) > 0 {
|
||||||
t.Fatalf("bad: %#v", warnings)
|
t.Fatalf("bad: %#v", warnings)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err == nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatal("should error")
|
||||||
}
|
|
||||||
|
|
||||||
if b.config.Image != DefaultImage {
|
|
||||||
t.Errorf("found %s, expected %s", b.config.Image, DefaultImage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := "ubuntu-14-04-x64"
|
expected := "ubuntu-14-04-x64"
|
||||||
|
|
|
@ -63,18 +63,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
||||||
c.APIToken = os.Getenv("DIGITALOCEAN_API_TOKEN")
|
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 == "" {
|
if c.SnapshotName == "" {
|
||||||
// Default to packer-{{ unix timestamp (utc) }}
|
// Default to packer-{{ unix timestamp (utc) }}
|
||||||
c.SnapshotName = "packer-{{timestamp}}"
|
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"))
|
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)
|
sshTimeout, err := time.ParseDuration(c.RawSSHTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = packer.MultiErrorAppend(
|
errs = packer.MultiErrorAppend(
|
||||||
|
|
Loading…
Reference in New Issue