Merge pull request #11869 from hashicorp/f-update-do-acctests
provider/digitalocean: Update digital ocean acceptance tests
This commit is contained in:
commit
67b0c3dfc6
|
@ -3,11 +3,13 @@ package digitalocean
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccDigitalOceanDroplet_importBasic(t *testing.T) {
|
func TestAccDigitalOceanDroplet_importBasic(t *testing.T) {
|
||||||
resourceName := "digitalocean_droplet.foobar"
|
resourceName := "digitalocean_droplet.foobar"
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -15,7 +17,7 @@ func TestAccDigitalOceanDroplet_importBasic(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanDropletConfig_basic,
|
Config: testAccCheckDigitalOceanDropletConfig_basic(rInt),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@ package digitalocean
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,6 +30,7 @@ func TestAccDigitalOceanFloatingIP_importBasicRegion(t *testing.T) {
|
||||||
|
|
||||||
func TestAccDigitalOceanFloatingIP_importBasicDroplet(t *testing.T) {
|
func TestAccDigitalOceanFloatingIP_importBasicDroplet(t *testing.T) {
|
||||||
resourceName := "digitalocean_floating_ip.foobar"
|
resourceName := "digitalocean_floating_ip.foobar"
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -36,7 +38,7 @@ func TestAccDigitalOceanFloatingIP_importBasicDroplet(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckDigitalOceanFloatingIPDestroy,
|
CheckDestroy: testAccCheckDigitalOceanFloatingIPDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanFloatingIPConfig_droplet,
|
Config: testAccCheckDigitalOceanFloatingIPConfig_droplet(rInt),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ func TestAccDigitalOceanSSHKey_importBasic(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckDigitalOceanSSHKeyDestroy,
|
CheckDestroy: testAccCheckDigitalOceanSSHKeyDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanSSHKeyConfig_basic,
|
Config: testAccCheckDigitalOceanSSHKeyConfig_basic(testAccValidImportPublicKey),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,12 +7,14 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/digitalocean/godo"
|
"github.com/digitalocean/godo"
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccDigitalOceanDroplet_Basic(t *testing.T) {
|
func TestAccDigitalOceanDroplet_Basic(t *testing.T) {
|
||||||
var droplet godo.Droplet
|
var droplet godo.Droplet
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -20,12 +22,42 @@ func TestAccDigitalOceanDroplet_Basic(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanDropletConfig_basic,
|
Config: testAccCheckDigitalOceanDropletConfig_basic(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
||||||
testAccCheckDigitalOceanDropletAttributes(&droplet),
|
testAccCheckDigitalOceanDropletAttributes(&droplet),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"digitalocean_droplet.foobar", "name", "foo"),
|
"digitalocean_droplet.foobar", "name", fmt.Sprintf("foo-%d", rInt)),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"digitalocean_droplet.foobar", "size", "512mb"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"digitalocean_droplet.foobar", "image", "centos-7-x64"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"digitalocean_droplet.foobar", "region", "nyc3"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"digitalocean_droplet.foobar", "user_data", "foobar"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAccDigitalOceanDroplet_withSSH(t *testing.T) {
|
||||||
|
var droplet godo.Droplet
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccCheckDigitalOceanDropletConfig_withSSH(rInt),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
||||||
|
testAccCheckDigitalOceanDropletAttributes(&droplet),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"digitalocean_droplet.foobar", "name", fmt.Sprintf("foo-%d", rInt)),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"digitalocean_droplet.foobar", "size", "512mb"),
|
"digitalocean_droplet.foobar", "size", "512mb"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -42,6 +74,7 @@ func TestAccDigitalOceanDroplet_Basic(t *testing.T) {
|
||||||
|
|
||||||
func TestAccDigitalOceanDroplet_Update(t *testing.T) {
|
func TestAccDigitalOceanDroplet_Update(t *testing.T) {
|
||||||
var droplet godo.Droplet
|
var droplet godo.Droplet
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -49,20 +82,22 @@ func TestAccDigitalOceanDroplet_Update(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanDropletConfig_basic,
|
Config: testAccCheckDigitalOceanDropletConfig_basic(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
||||||
testAccCheckDigitalOceanDropletAttributes(&droplet),
|
testAccCheckDigitalOceanDropletAttributes(&droplet),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"digitalocean_droplet.foobar", "name", fmt.Sprintf("foo-%d", rInt)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanDropletConfig_RenameAndResize,
|
Config: testAccCheckDigitalOceanDropletConfig_RenameAndResize(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
||||||
testAccCheckDigitalOceanDropletRenamedAndResized(&droplet),
|
testAccCheckDigitalOceanDropletRenamedAndResized(&droplet),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"digitalocean_droplet.foobar", "name", "baz"),
|
"digitalocean_droplet.foobar", "name", fmt.Sprintf("baz-%d", rInt)),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"digitalocean_droplet.foobar", "size", "1gb"),
|
"digitalocean_droplet.foobar", "size", "1gb"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -75,6 +110,7 @@ func TestAccDigitalOceanDroplet_Update(t *testing.T) {
|
||||||
|
|
||||||
func TestAccDigitalOceanDroplet_ResizeWithOutDisk(t *testing.T) {
|
func TestAccDigitalOceanDroplet_ResizeWithOutDisk(t *testing.T) {
|
||||||
var droplet godo.Droplet
|
var droplet godo.Droplet
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -82,18 +118,22 @@ func TestAccDigitalOceanDroplet_ResizeWithOutDisk(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanDropletConfig_basic,
|
Config: testAccCheckDigitalOceanDropletConfig_basic(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
||||||
testAccCheckDigitalOceanDropletAttributes(&droplet),
|
testAccCheckDigitalOceanDropletAttributes(&droplet),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"digitalocean_droplet.foobar", "name", fmt.Sprintf("foo-%d", rInt)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanDropletConfig_resize_without_disk,
|
Config: testAccCheckDigitalOceanDropletConfig_resize_without_disk(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
||||||
testAccCheckDigitalOceanDropletResizeWithOutDisk(&droplet),
|
testAccCheckDigitalOceanDropletResizeWithOutDisk(&droplet),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"digitalocean_droplet.foobar", "name", fmt.Sprintf("foo-%d", rInt)),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"digitalocean_droplet.foobar", "size", "1gb"),
|
"digitalocean_droplet.foobar", "size", "1gb"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -106,6 +146,7 @@ func TestAccDigitalOceanDroplet_ResizeWithOutDisk(t *testing.T) {
|
||||||
|
|
||||||
func TestAccDigitalOceanDroplet_UpdateUserData(t *testing.T) {
|
func TestAccDigitalOceanDroplet_UpdateUserData(t *testing.T) {
|
||||||
var afterCreate, afterUpdate godo.Droplet
|
var afterCreate, afterUpdate godo.Droplet
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -113,17 +154,21 @@ func TestAccDigitalOceanDroplet_UpdateUserData(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanDropletConfig_basic,
|
Config: testAccCheckDigitalOceanDropletConfig_basic(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &afterCreate),
|
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &afterCreate),
|
||||||
testAccCheckDigitalOceanDropletAttributes(&afterCreate),
|
testAccCheckDigitalOceanDropletAttributes(&afterCreate),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"digitalocean_droplet.foobar", "name", fmt.Sprintf("foo-%d", rInt)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanDropletConfig_userdata_update,
|
Config: testAccCheckDigitalOceanDropletConfig_userdata_update(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &afterUpdate),
|
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &afterUpdate),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"digitalocean_droplet.foobar", "name", fmt.Sprintf("foo-%d", rInt)),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"digitalocean_droplet.foobar",
|
"digitalocean_droplet.foobar",
|
||||||
"user_data",
|
"user_data",
|
||||||
|
@ -138,6 +183,7 @@ func TestAccDigitalOceanDroplet_UpdateUserData(t *testing.T) {
|
||||||
|
|
||||||
func TestAccDigitalOceanDroplet_UpdateTags(t *testing.T) {
|
func TestAccDigitalOceanDroplet_UpdateTags(t *testing.T) {
|
||||||
var afterCreate, afterUpdate godo.Droplet
|
var afterCreate, afterUpdate godo.Droplet
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -145,17 +191,21 @@ func TestAccDigitalOceanDroplet_UpdateTags(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanDropletConfig_basic,
|
Config: testAccCheckDigitalOceanDropletConfig_basic(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &afterCreate),
|
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &afterCreate),
|
||||||
testAccCheckDigitalOceanDropletAttributes(&afterCreate),
|
testAccCheckDigitalOceanDropletAttributes(&afterCreate),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"digitalocean_droplet.foobar", "name", fmt.Sprintf("foo-%d", rInt)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanDropletConfig_tag_update,
|
Config: testAccCheckDigitalOceanDropletConfig_tag_update(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &afterUpdate),
|
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &afterUpdate),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"digitalocean_droplet.foobar", "name", fmt.Sprintf("foo-%d", rInt)),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"digitalocean_droplet.foobar",
|
"digitalocean_droplet.foobar",
|
||||||
"tags.#",
|
"tags.#",
|
||||||
|
@ -172,6 +222,7 @@ func TestAccDigitalOceanDroplet_UpdateTags(t *testing.T) {
|
||||||
|
|
||||||
func TestAccDigitalOceanDroplet_PrivateNetworkingIpv6(t *testing.T) {
|
func TestAccDigitalOceanDroplet_PrivateNetworkingIpv6(t *testing.T) {
|
||||||
var droplet godo.Droplet
|
var droplet godo.Droplet
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -179,7 +230,7 @@ func TestAccDigitalOceanDroplet_PrivateNetworkingIpv6(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanDropletConfig_PrivateNetworkingIpv6,
|
Config: testAccCheckDigitalOceanDropletConfig_PrivateNetworkingIpv6(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
|
||||||
testAccCheckDigitalOceanDropletAttributes_PrivateNetworkingIpv6(&droplet),
|
testAccCheckDigitalOceanDropletAttributes_PrivateNetworkingIpv6(&droplet),
|
||||||
|
@ -236,9 +287,6 @@ func testAccCheckDigitalOceanDropletAttributes(droplet *godo.Droplet) resource.T
|
||||||
return fmt.Errorf("Bad region_slug: %s", droplet.Region.Slug)
|
return fmt.Errorf("Bad region_slug: %s", droplet.Region.Slug)
|
||||||
}
|
}
|
||||||
|
|
||||||
if droplet.Name != "foo" {
|
|
||||||
return fmt.Errorf("Bad name: %s", droplet.Name)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -250,10 +298,6 @@ func testAccCheckDigitalOceanDropletRenamedAndResized(droplet *godo.Droplet) res
|
||||||
return fmt.Errorf("Bad size_slug: %s", droplet.SizeSlug)
|
return fmt.Errorf("Bad size_slug: %s", droplet.SizeSlug)
|
||||||
}
|
}
|
||||||
|
|
||||||
if droplet.Name != "baz" {
|
|
||||||
return fmt.Errorf("Bad name: %s", droplet.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
if droplet.Disk != 30 {
|
if droplet.Disk != 30 {
|
||||||
return fmt.Errorf("Bad disk: %d", droplet.Disk)
|
return fmt.Errorf("Bad disk: %d", droplet.Disk)
|
||||||
}
|
}
|
||||||
|
@ -292,10 +336,6 @@ func testAccCheckDigitalOceanDropletAttributes_PrivateNetworkingIpv6(droplet *go
|
||||||
return fmt.Errorf("Bad region_slug: %s", droplet.Region.Slug)
|
return fmt.Errorf("Bad region_slug: %s", droplet.Region.Slug)
|
||||||
}
|
}
|
||||||
|
|
||||||
if droplet.Name != "baz" {
|
|
||||||
return fmt.Errorf("Bad name: %s", droplet.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
if findIPv4AddrByType(droplet, "private") == "" {
|
if findIPv4AddrByType(droplet, "private") == "" {
|
||||||
return fmt.Errorf("No ipv4 private: %s", findIPv4AddrByType(droplet, "private"))
|
return fmt.Errorf("No ipv4 private: %s", findIPv4AddrByType(droplet, "private"))
|
||||||
}
|
}
|
||||||
|
@ -371,105 +411,97 @@ func testAccCheckDigitalOceanDropletRecreated(t *testing.T,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var testAccCheckDigitalOceanDropletConfig_basic = fmt.Sprintf(`
|
func testAccCheckDigitalOceanDropletConfig_basic(rInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "digitalocean_droplet" "foobar" {
|
||||||
|
name = "foo-%d"
|
||||||
|
size = "512mb"
|
||||||
|
image = "centos-7-x64"
|
||||||
|
region = "nyc3"
|
||||||
|
user_data = "foobar"
|
||||||
|
}`, rInt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccCheckDigitalOceanDropletConfig_withSSH(rInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "digitalocean_ssh_key" "foobar" {
|
resource "digitalocean_ssh_key" "foobar" {
|
||||||
name = "foobar"
|
name = "foobar-%d"
|
||||||
public_key = "%s"
|
public_key = "%s"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "digitalocean_droplet" "foobar" {
|
resource "digitalocean_droplet" "foobar" {
|
||||||
name = "foo"
|
name = "foo-%d"
|
||||||
size = "512mb"
|
size = "512mb"
|
||||||
image = "centos-7-x64"
|
image = "centos-7-x64"
|
||||||
region = "nyc3"
|
region = "nyc3"
|
||||||
user_data = "foobar"
|
user_data = "foobar"
|
||||||
ssh_keys = ["${digitalocean_ssh_key.foobar.id}"]
|
ssh_keys = ["${digitalocean_ssh_key.foobar.id}"]
|
||||||
|
}`, rInt, testAccValidPublicKey, rInt)
|
||||||
}
|
}
|
||||||
`, testAccValidPublicKey)
|
|
||||||
|
|
||||||
var testAccCheckDigitalOceanDropletConfig_tag_update = fmt.Sprintf(`
|
func testAccCheckDigitalOceanDropletConfig_tag_update(rInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "digitalocean_tag" "barbaz" {
|
resource "digitalocean_tag" "barbaz" {
|
||||||
name = "barbaz"
|
name = "barbaz"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "digitalocean_ssh_key" "foobar" {
|
|
||||||
name = "foobar"
|
|
||||||
public_key = "%s"
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "digitalocean_droplet" "foobar" {
|
resource "digitalocean_droplet" "foobar" {
|
||||||
name = "foo"
|
name = "foo-%d"
|
||||||
size = "512mb"
|
size = "512mb"
|
||||||
image = "centos-7-x64"
|
image = "centos-7-x64"
|
||||||
region = "nyc3"
|
region = "nyc3"
|
||||||
user_data = "foobar"
|
user_data = "foobar"
|
||||||
ssh_keys = ["${digitalocean_ssh_key.foobar.id}"]
|
|
||||||
tags = ["${digitalocean_tag.barbaz.id}"]
|
tags = ["${digitalocean_tag.barbaz.id}"]
|
||||||
}
|
}
|
||||||
`, testAccValidPublicKey)
|
`, rInt)
|
||||||
|
|
||||||
var testAccCheckDigitalOceanDropletConfig_userdata_update = fmt.Sprintf(`
|
|
||||||
resource "digitalocean_ssh_key" "foobar" {
|
|
||||||
name = "foobar"
|
|
||||||
public_key = "%s"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckDigitalOceanDropletConfig_userdata_update(rInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "digitalocean_droplet" "foobar" {
|
resource "digitalocean_droplet" "foobar" {
|
||||||
name = "foo"
|
name = "foo-%d"
|
||||||
size = "512mb"
|
size = "512mb"
|
||||||
image = "centos-7-x64"
|
image = "centos-7-x64"
|
||||||
region = "nyc3"
|
region = "nyc3"
|
||||||
user_data = "foobar foobar"
|
user_data = "foobar foobar"
|
||||||
ssh_keys = ["${digitalocean_ssh_key.foobar.id}"]
|
|
||||||
}
|
}
|
||||||
`, testAccValidPublicKey)
|
`, rInt)
|
||||||
|
|
||||||
var testAccCheckDigitalOceanDropletConfig_RenameAndResize = fmt.Sprintf(`
|
|
||||||
resource "digitalocean_ssh_key" "foobar" {
|
|
||||||
name = "foobar"
|
|
||||||
public_key = "%s"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckDigitalOceanDropletConfig_RenameAndResize(rInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "digitalocean_droplet" "foobar" {
|
resource "digitalocean_droplet" "foobar" {
|
||||||
name = "baz"
|
name = "baz-%d"
|
||||||
size = "1gb"
|
size = "1gb"
|
||||||
image = "centos-7-x64"
|
image = "centos-7-x64"
|
||||||
region = "nyc3"
|
region = "nyc3"
|
||||||
ssh_keys = ["${digitalocean_ssh_key.foobar.id}"]
|
|
||||||
}
|
}
|
||||||
`, testAccValidPublicKey)
|
`, rInt)
|
||||||
|
|
||||||
var testAccCheckDigitalOceanDropletConfig_resize_without_disk = fmt.Sprintf(`
|
|
||||||
resource "digitalocean_ssh_key" "foobar" {
|
|
||||||
name = "foobar"
|
|
||||||
public_key = "%s"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckDigitalOceanDropletConfig_resize_without_disk(rInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "digitalocean_droplet" "foobar" {
|
resource "digitalocean_droplet" "foobar" {
|
||||||
name = "foo"
|
name = "foo-%d"
|
||||||
size = "1gb"
|
size = "1gb"
|
||||||
image = "centos-7-x64"
|
image = "centos-7-x64"
|
||||||
region = "nyc3"
|
region = "nyc3"
|
||||||
user_data = "foobar"
|
user_data = "foobar"
|
||||||
ssh_keys = ["${digitalocean_ssh_key.foobar.id}"]
|
|
||||||
resize_disk = false
|
resize_disk = false
|
||||||
}
|
}
|
||||||
`, testAccValidPublicKey)
|
`, rInt)
|
||||||
|
|
||||||
// IPV6 only in singapore
|
|
||||||
var testAccCheckDigitalOceanDropletConfig_PrivateNetworkingIpv6 = fmt.Sprintf(`
|
|
||||||
resource "digitalocean_ssh_key" "foobar" {
|
|
||||||
name = "foobar"
|
|
||||||
public_key = "%s"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IPV6 only in singapore
|
||||||
|
func testAccCheckDigitalOceanDropletConfig_PrivateNetworkingIpv6(rInt int) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "digitalocean_droplet" "foobar" {
|
resource "digitalocean_droplet" "foobar" {
|
||||||
name = "baz"
|
name = "baz-%d"
|
||||||
size = "1gb"
|
size = "1gb"
|
||||||
image = "centos-7-x64"
|
image = "centos-7-x64"
|
||||||
region = "sgp1"
|
region = "sgp1"
|
||||||
ipv6 = true
|
ipv6 = true
|
||||||
private_networking = true
|
private_networking = true
|
||||||
ssh_keys = ["${digitalocean_ssh_key.foobar.id}"]
|
|
||||||
}
|
}
|
||||||
`, testAccValidPublicKey)
|
`, rInt)
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/digitalocean/godo"
|
"github.com/digitalocean/godo"
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -31,6 +32,7 @@ func TestAccDigitalOceanFloatingIP_Region(t *testing.T) {
|
||||||
|
|
||||||
func TestAccDigitalOceanFloatingIP_Droplet(t *testing.T) {
|
func TestAccDigitalOceanFloatingIP_Droplet(t *testing.T) {
|
||||||
var floatingIP godo.FloatingIP
|
var floatingIP godo.FloatingIP
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -38,7 +40,7 @@ func TestAccDigitalOceanFloatingIP_Droplet(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckDigitalOceanFloatingIPDestroy,
|
CheckDestroy: testAccCheckDigitalOceanFloatingIPDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanFloatingIPConfig_droplet,
|
Config: testAccCheckDigitalOceanFloatingIPConfig_droplet(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckDigitalOceanFloatingIPExists("digitalocean_floating_ip.foobar", &floatingIP),
|
testAccCheckDigitalOceanFloatingIPExists("digitalocean_floating_ip.foobar", &floatingIP),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -104,23 +106,19 @@ resource "digitalocean_floating_ip" "foobar" {
|
||||||
region = "nyc3"
|
region = "nyc3"
|
||||||
}`
|
}`
|
||||||
|
|
||||||
var testAccCheckDigitalOceanFloatingIPConfig_droplet = fmt.Sprintf(`
|
func testAccCheckDigitalOceanFloatingIPConfig_droplet(rInt int) string {
|
||||||
resource "digitalocean_ssh_key" "foobar" {
|
return fmt.Sprintf(`
|
||||||
name = "foobar"
|
|
||||||
public_key = "%s"
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "digitalocean_droplet" "foobar" {
|
resource "digitalocean_droplet" "foobar" {
|
||||||
name = "baz"
|
name = "baz-%d"
|
||||||
size = "1gb"
|
size = "1gb"
|
||||||
image = "centos-7-x64"
|
image = "centos-7-x64"
|
||||||
region = "nyc3"
|
region = "nyc3"
|
||||||
ipv6 = true
|
ipv6 = true
|
||||||
private_networking = true
|
private_networking = true
|
||||||
ssh_keys = ["${digitalocean_ssh_key.foobar.id}"]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "digitalocean_floating_ip" "foobar" {
|
resource "digitalocean_floating_ip" "foobar" {
|
||||||
droplet_id = "${digitalocean_droplet.foobar.id}"
|
droplet_id = "${digitalocean_droplet.foobar.id}"
|
||||||
region = "${digitalocean_droplet.foobar.region}"
|
region = "${digitalocean_droplet.foobar.region}"
|
||||||
}`, testAccValidPublicKey)
|
}`, rInt)
|
||||||
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestAccDigitalOceanSSHKey_Basic(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckDigitalOceanSSHKeyDestroy,
|
CheckDestroy: testAccCheckDigitalOceanSSHKeyDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccCheckDigitalOceanSSHKeyConfig_basic,
|
Config: testAccCheckDigitalOceanSSHKeyConfig_basic(testAccValidPublicKey),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckDigitalOceanSSHKeyExists("digitalocean_ssh_key.foobar", &key),
|
testAccCheckDigitalOceanSSHKeyExists("digitalocean_ssh_key.foobar", &key),
|
||||||
testAccCheckDigitalOceanSSHKeyAttributes(&key),
|
testAccCheckDigitalOceanSSHKeyAttributes(&key),
|
||||||
|
@ -105,10 +105,13 @@ func testAccCheckDigitalOceanSSHKeyExists(n string, key *godo.Key) resource.Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var testAccCheckDigitalOceanSSHKeyConfig_basic = fmt.Sprintf(`
|
func testAccCheckDigitalOceanSSHKeyConfig_basic(key string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
resource "digitalocean_ssh_key" "foobar" {
|
resource "digitalocean_ssh_key" "foobar" {
|
||||||
name = "foobar"
|
name = "foobar"
|
||||||
public_key = "%s"
|
public_key = "%s"
|
||||||
}`, testAccValidPublicKey)
|
}`, key)
|
||||||
|
}
|
||||||
|
|
||||||
var testAccValidPublicKey = `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR`
|
var testAccValidPublicKey = `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR`
|
||||||
|
var testAccValidImportPublicKey = `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwelf/LV8TKOd6ZCcDwU9L8YRdVwfR2q8E+Bzamcxwb1U41vnfyvEZbzx0aeXimdHipOql0SG2tu9Z+bzekROVc13OP/gtGRlWwZ9RoKE8hFHanhi0K2tC6OWagsvmHpW/xptsYAo2k+eRJJo0iy/hLNG2c1v5rrjg6xwnSL3+a7bFM4xNDux5sNYCmxIBfIL+4rQ8XBlxsjMrGoev/uumZ0yc75JtBCOSZbdie936pvVmoAf4nhxNbe5lOxp+18zHhBbO2fjhux4xmf4hLM2gHsdBGqtnphzLh3d1+uMIpv7ZMTKN7pBw53xQxw7hhDYuNKc8FkQ8xK6IL5bu/Ar/`
|
||||||
|
|
|
@ -97,6 +97,7 @@ func TestAccDigitalOceanVolume_Droplet(t *testing.T) {
|
||||||
volume = godo.Volume{Name: fmt.Sprintf("volume-%s", acctest.RandString(10))}
|
volume = godo.Volume{Name: fmt.Sprintf("volume-%s", acctest.RandString(10))}
|
||||||
droplet godo.Droplet
|
droplet godo.Droplet
|
||||||
)
|
)
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -105,7 +106,7 @@ func TestAccDigitalOceanVolume_Droplet(t *testing.T) {
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: fmt.Sprintf(
|
Config: fmt.Sprintf(
|
||||||
testAccCheckDigitalOceanVolumeConfig_droplet,
|
testAccCheckDigitalOceanVolumeConfig_droplet(rInt, volume.Name),
|
||||||
testAccValidPublicKey, volume.Name,
|
testAccValidPublicKey, volume.Name,
|
||||||
),
|
),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
@ -120,12 +121,8 @@ func TestAccDigitalOceanVolume_Droplet(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const testAccCheckDigitalOceanVolumeConfig_droplet = `
|
func testAccCheckDigitalOceanVolumeConfig_droplet(rInt int, vName string) string {
|
||||||
resource "digitalocean_ssh_key" "foobar" {
|
return fmt.Sprintf(`
|
||||||
name = "foobar"
|
|
||||||
public_key = "%s"
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "digitalocean_volume" "foobar" {
|
resource "digitalocean_volume" "foobar" {
|
||||||
region = "nyc1"
|
region = "nyc1"
|
||||||
name = "%s"
|
name = "%s"
|
||||||
|
@ -134,7 +131,7 @@ resource "digitalocean_volume" "foobar" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "digitalocean_droplet" "foobar" {
|
resource "digitalocean_droplet" "foobar" {
|
||||||
name = "baz"
|
name = "baz-%d"
|
||||||
size = "1gb"
|
size = "1gb"
|
||||||
image = "coreos-stable"
|
image = "coreos-stable"
|
||||||
region = "nyc1"
|
region = "nyc1"
|
||||||
|
@ -142,4 +139,5 @@ resource "digitalocean_droplet" "foobar" {
|
||||||
private_networking = true
|
private_networking = true
|
||||||
ssh_keys = ["${digitalocean_ssh_key.foobar.id}"]
|
ssh_keys = ["${digitalocean_ssh_key.foobar.id}"]
|
||||||
volume_ids = ["${digitalocean_volume.foobar.id}"]
|
volume_ids = ["${digitalocean_volume.foobar.id}"]
|
||||||
}`
|
}`, vName, rInt)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue