Skip to content

Commit

Permalink
added some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
imaskm committed Dec 9, 2024
1 parent ba7f286 commit fded416
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion digitalocean/droplet/resource_droplet.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ func waitForDropletDestroy(ctx context.Context, d *schema.ResourceData, meta int

stateConf := &retry.StateChangeConf{
Pending: []string{"active", "off"},
Target: []string{"archived"},
Target: []string{"archive"},
Refresh: dropletStateRefreshFunc(ctx, d, "status", meta),
Timeout: 60 * time.Second,
Delay: 10 * time.Second,
Expand Down
4 changes: 2 additions & 2 deletions digitalocean/reservedipv6/datasource_reserved_ipv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func TestAccDataSourceDigitalOceanReservedIPV6_Basic(t *testing.T) {
var reservedIPv6 godo.ReservedIPV6

expectedURNRegex, _ := regexp.Compile(`do:reservedipv6:/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i`)
expectedURNRegex, _ := regexp.Compile(`do:reservedipv6:` + ipv6Regex)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
Expand All @@ -40,7 +40,7 @@ func TestAccDataSourceDigitalOceanReservedIPV6_Basic(t *testing.T) {
func TestAccDataSourceDigitalOceanReservedIPV6_FindsReservedIP(t *testing.T) {
var reservedIPv6 godo.ReservedIPV6

expectedURNRegex, _ := regexp.Compile(`do:reservedipv6:/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i`)
expectedURNRegex, _ := regexp.Compile(`do:reservedipv6:` + ipv6Regex)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
Expand Down
2 changes: 1 addition & 1 deletion digitalocean/reservedipv6/resource_reserved_ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func resourceDigitalOceanReservedIPV6Delete(ctx context.Context, d *schema.Resou

log.Printf("[INFO] Deleting reserved IPv6: %s", d.Id())
_, err := client.ReservedIPV6s.Delete(context.Background(), d.Id())
if err != nil {
if err != nil && strings.Contains(err.Error(), "404") {
return diag.Errorf("Error deleting reserved IPv6: %s", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ResourceDigitalOceanReservedIPV6Assignment() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.IsIPv4Address,
ValidateFunc: validation.IsIPv6Address,
},
"droplet_id": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -100,7 +100,7 @@ func resourceDigitalOceanReservedIPV6AssignmentDelete(ctx context.Context, d *sc

if reservedIPv6.Droplet.ID == dropletID {
log.Printf("[INFO] Unassigning the reserved IPv6 from the Droplet")
action, _, err := client.ReservedIPActions.Unassign(context.Background(), ipAddress)
action, _, err := client.ReservedIPV6Actions.Unassign(context.Background(), ipAddress)
if err != nil {
return diag.Errorf("Error unassigning reserved IPv6 (%s) from the droplet: %s", ipAddress, err)
}
Expand Down Expand Up @@ -146,7 +146,7 @@ func newReservedIPV6AssignmentStateRefreshFunc(
log.Printf("[INFO] Refreshing the reserved IPv6 state")
action, _, err := client.Actions.Get(context.Background(), actionID)
if err != nil {
return nil, "", fmt.Errorf("error retrieving reserved IPv6 (%s) ActionId (%d): %s", d.Get("ip_address").(string), actionID, err)
return nil, "", fmt.Errorf("error retrieving reserved IPv6 (%s) ActionId (%d): %s", d.Get("ip_address"), actionID, err)
}

log.Printf("[INFO] The reserved IPv6 Action Status is %s", action.Status)
Expand Down
42 changes: 20 additions & 22 deletions digitalocean/reservedipv6/resource_reserved_ipv6_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestAccDigitalOceanReservedIPV6Assignment(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6AttachmentExists("digitalocean_reserved_ipv6_assignment.foobar"),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "id", regexp.MustCompile("[0-9.]+")),
"digitalocean_reserved_ipv6_assignment.foobar", "id", regexp.MustCompile(ipv6Regex)),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "droplet_id", regexp.MustCompile("[0-9]+")),
),
Expand All @@ -37,7 +37,7 @@ func TestAccDigitalOceanReservedIPV6Assignment(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6AttachmentExists("digitalocean_reserved_ipv6_assignment.foobar"),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "id", regexp.MustCompile("[0-9.]+")),
"digitalocean_reserved_ipv6_assignment.foobar", "id", regexp.MustCompile(ipv6Regex)),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "droplet_id", regexp.MustCompile("[0-9]+")),
),
Expand All @@ -47,7 +47,7 @@ func TestAccDigitalOceanReservedIPV6Assignment(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6Exists("digitalocean_reserved_ipv6.foobar", &reservedIPv6),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6.foobar", "ip", regexp.MustCompile("[0-9.]+")),
"digitalocean_reserved_ipv6.foobar", "ip", regexp.MustCompile(ipv6Regex)),
),
},
},
Expand All @@ -65,7 +65,7 @@ func TestAccDigitalOceanReservedIPV6Assignment_createBeforeDestroy(t *testing.T)
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6AttachmentExists("digitalocean_reserved_ipv6_assignment.foobar"),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "id", regexp.MustCompile("[0-9.]+")),
"digitalocean_reserved_ipv6_assignment.foobar", "id", regexp.MustCompile(ipv6Regex)),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "droplet_id", regexp.MustCompile("[0-9]+")),
),
Expand All @@ -75,7 +75,7 @@ func TestAccDigitalOceanReservedIPV6Assignment_createBeforeDestroy(t *testing.T)
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanReservedIPV6AttachmentExists("digitalocean_reserved_ipv6_assignment.foobar"),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "id", regexp.MustCompile("[0-9.]+")),
"digitalocean_reserved_ipv6_assignment.foobar", "id", regexp.MustCompile(ipv6Regex)),
resource.TestMatchResourceAttr(
"digitalocean_reserved_ipv6_assignment.foobar", "droplet_id", regexp.MustCompile("[0-9]+")),
),
Expand Down Expand Up @@ -103,7 +103,7 @@ func testAccCheckDigitalOceanReservedIPV6AttachmentExists(n string) resource.Tes
client := acceptance.TestAccProvider.Meta().(*config.CombinedConfig).GodoClient()

// Try to find the ReservedIP
foundReservedIP, _, err := client.ReservedIPs.Get(context.Background(), fipID)
foundReservedIP, _, err := client.ReservedIPV6s.Get(context.Background(), fipID)
if err != nil {
return err
}
Expand All @@ -122,13 +122,12 @@ resource "digitalocean_reserved_ipv6" "foobar" {
}
resource "digitalocean_droplet" "foobar" {
count = 2
name = "tf-acc-test-${count.index}"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
private_networking = true
count = 2
name = "tf-acc-test-${count.index}"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
}
resource "digitalocean_reserved_ipv6_assignment" "foobar" {
Expand All @@ -143,13 +142,12 @@ resource "digitalocean_reserved_ipv6" "foobar" {
}
resource "digitalocean_droplet" "foobar" {
count = 2
name = "tf-acc-test-${count.index}"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
private_networking = true
count = 2
name = "tf-acc-test-${count.index}"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
}
resource "digitalocean_reserved_ipv6_assignment" "foobar" {
Expand Down Expand Up @@ -191,7 +189,7 @@ resource "digitalocean_reserved_ipv6" "foobar" {
}
resource "digitalocean_reserved_ipv6_assignment" "foobar" {
ip = digitalocean_reserved_ipv6.foobar.id
ip = digitalocean_reserved_ipv6.foobar.ip
droplet_id = digitalocean_droplet.foobar.id
lifecycle {
Expand All @@ -217,7 +215,7 @@ resource "digitalocean_reserved_ipv6" "foobar" {
}
resource "digitalocean_reserved_ipv6_assignment" "foobar" {
ip = digitalocean_reserved_ipv6.foobar.id
ip = digitalocean_reserved_ipv6.foobar.ip
droplet_id = digitalocean_droplet.foobar.id
lifecycle {
Expand Down
14 changes: 9 additions & 5 deletions digitalocean/reservedipv6/resource_reserved_ipv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

const ipv6Regex = "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$"

func TestAccDigitalOceanReservedIPV6_RegionSlug(t *testing.T) {
var reservedIPv6 godo.ReservedIPV6

expectedURNRegex, _ := regexp.Compile(`do:reservedipv6:/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i`)
expectedURNRegex, _ := regexp.Compile(`do:reservedipv6:` + ipv6Regex)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
Expand Down Expand Up @@ -133,9 +135,10 @@ func testAccCheckDigitalOceanReservedIPV6Config_droplet(name string) string {
resource "digitalocean_droplet" "foobar" {
name = "%s"
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
private_networking = true
}
resource "digitalocean_reserved_ipv6" "foobar" {
Expand All @@ -151,7 +154,8 @@ resource "digitalocean_droplet" "baz" {
size = "s-1vcpu-1gb"
image = "ubuntu-22-04-x64"
region = "nyc3"
ipv6 = true
ipv6 = true
private_networking = true
}
resource "digitalocean_reserved_ipv6" "foobar" {
Expand Down

0 comments on commit fded416

Please sign in to comment.