providers/digitalocean: fix ip address when using private networking

This adds a new `ipv4_address_private` and `ipv4_address_public`
computed attr. Also pulls in upstream changes from pearkes/digitalocean
This commit is contained in:
Jack Pearkes 2014-07-29 18:58:48 -04:00
parent 5f2146999f
commit 872acb3740
3 changed files with 94 additions and 5 deletions

View File

@ -83,7 +83,7 @@ func resource_digitalocean_droplet_create(
// Initialize the connection info
rs.ConnInfo["type"] = "ssh"
rs.ConnInfo["host"] = droplet.IPV4Address()
rs.ConnInfo["host"] = droplet.IPV4Address("public")
return resource_digitalocean_droplet_update_state(rs, droplet)
}
@ -246,8 +246,10 @@ func resource_digitalocean_droplet_diff(
ComputedAttrs: []string{
"backups",
"ipv4_address",
"ipv4_address_private",
"ipv6",
"ipv6_address",
"ipv6_address_private",
"locked",
"private_networking",
"status",
@ -270,14 +272,20 @@ func resource_digitalocean_droplet_update_state(
s.Attributes["image"] = droplet.ImageSlug()
}
if droplet.IPV6Address() != "" {
if droplet.IPV6Address("public") != "" {
s.Attributes["ipv6"] = "true"
s.Attributes["ipv6_address"] = droplet.IPV6Address()
s.Attributes["ipv6_address"] = droplet.IPV6Address("public")
s.Attributes["ipv6_address_private"] = droplet.IPV6Address("private")
}
s.Attributes["ipv4_address"] = droplet.IPV4Address()
s.Attributes["ipv4_address"] = droplet.IPV4Address("public")
s.Attributes["ipv4_address_private"] = droplet.IPV4Address("private")
s.Attributes["locked"] = droplet.IsLocked()
s.Attributes["private_networking"] = droplet.NetworkingType()
if droplet.NetworkingType() == "private" {
s.Attributes["private_networking"] = "true"
}
s.Attributes["size"] = droplet.SizeSlug()
s.Attributes["status"] = droplet.Status

View File

@ -68,6 +68,29 @@ func TestAccDigitalOceanDroplet_Update(t *testing.T) {
})
}
func TestAccDigitalOceanDroplet_PrivateNetworkingIpv6(t *testing.T) {
var droplet digitalocean.Droplet
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDigitalOceanDropletDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckDigitalOceanDropletConfig_PrivateNetworkingIpv6,
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet),
testAccCheckDigitalOceanDropletAttributes_PrivateNetworkingIpv6(&droplet),
resource.TestCheckResourceAttr(
"digitalocean_droplet.foobar", "private_networking", "true"),
resource.TestCheckResourceAttr(
"digitalocean_droplet.foobar", "ipv6", "true"),
),
},
},
})
}
func testAccCheckDigitalOceanDropletDestroy(s *terraform.State) error {
client := testAccProvider.client
@ -127,6 +150,50 @@ func testAccCheckDigitalOceanDropletRenamedAndResized(droplet *digitalocean.Drop
return nil
}
}
func testAccCheckDigitalOceanDropletAttributes_PrivateNetworkingIpv6(droplet *digitalocean.Droplet) resource.TestCheckFunc {
return func(s *terraform.State) error {
if droplet.ImageSlug() != "centos-5-8-x32" {
return fmt.Errorf("Bad image_slug: %s", droplet.ImageSlug())
}
if droplet.SizeSlug() != "1gb" {
return fmt.Errorf("Bad size_slug: %s", droplet.SizeSlug())
}
if droplet.RegionSlug() != "sgp1" {
return fmt.Errorf("Bad region_slug: %s", droplet.RegionSlug())
}
if droplet.Name != "baz" {
return fmt.Errorf("Bad name: %s", droplet.Name)
}
if droplet.IPV4Address("private") == "" {
return fmt.Errorf("No ipv4 private: %s", droplet.IPV4Address("private"))
}
// if droplet.IPV6Address("private") == "" {
// return fmt.Errorf("No ipv6 private: %s", droplet.IPV6Address("private"))
// }
if droplet.NetworkingType() != "private" {
return fmt.Errorf("Bad networking type: %s", droplet.NetworkingType())
}
if droplet.IPV4Address("public") == "" {
return fmt.Errorf("No ipv4 public: %s", droplet.IPV4Address("public"))
}
if droplet.IPV6Address("public") == "" {
return fmt.Errorf("No ipv6 public: %s", droplet.IPV6Address("public"))
}
return nil
}
}
func testAccCheckDigitalOceanDropletExists(n string, droplet *digitalocean.Droplet) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
@ -187,3 +254,15 @@ resource "digitalocean_droplet" "foobar" {
region = "nyc2"
}
`
// IPV6 only in singapore
const testAccCheckDigitalOceanDropletConfig_PrivateNetworkingIpv6 = `
resource "digitalocean_droplet" "foobar" {
name = "baz"
size = "1gb"
image = "centos-5-8-x32"
region = "sgp1"
ipv6 = true
private_networking = true
}
`

View File

@ -45,7 +45,9 @@ The following attributes are exported:
* `image` - The image of the droplet
* `ipv6` - Is IPv6 enabled
* `ipv6_address` - The IPv6 address
* `ipv6_address_private` - The private networking IPv6 address
* `ipv4_address` - The IPv4 address
* `ipv4_address_private` - The private networking IPv4 address
* `locked` - Is the Droplet locked
* `private_networking` - Is private networking enabled
* `size` - The instance size