From fded4161154df69679c7674c163e05642ccaaa4e Mon Sep 17 00:00:00 2001 From: Ashwani Date: Mon, 9 Dec 2024 22:53:15 +0530 Subject: [PATCH] added some fixes --- digitalocean/droplet/resource_droplet.go | 2 +- .../datasource_reserved_ipv6_test.go | 4 +- .../reservedipv6/resource_reserved_ipv6.go | 2 +- .../resource_reserved_ipv6_assignment.go | 6 +-- .../resource_reserved_ipv6_assignment_test.go | 42 +++++++++---------- .../resource_reserved_ipv6_test.go | 14 ++++--- 6 files changed, 36 insertions(+), 34 deletions(-) diff --git a/digitalocean/droplet/resource_droplet.go b/digitalocean/droplet/resource_droplet.go index 81010de32..97bffa284 100644 --- a/digitalocean/droplet/resource_droplet.go +++ b/digitalocean/droplet/resource_droplet.go @@ -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, diff --git a/digitalocean/reservedipv6/datasource_reserved_ipv6_test.go b/digitalocean/reservedipv6/datasource_reserved_ipv6_test.go index c66664188..2d933807d 100644 --- a/digitalocean/reservedipv6/datasource_reserved_ipv6_test.go +++ b/digitalocean/reservedipv6/datasource_reserved_ipv6_test.go @@ -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) }, @@ -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) }, diff --git a/digitalocean/reservedipv6/resource_reserved_ipv6.go b/digitalocean/reservedipv6/resource_reserved_ipv6.go index a46956d53..f8db4c651 100644 --- a/digitalocean/reservedipv6/resource_reserved_ipv6.go +++ b/digitalocean/reservedipv6/resource_reserved_ipv6.go @@ -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) } diff --git a/digitalocean/reservedipv6/resource_reserved_ipv6_assignment.go b/digitalocean/reservedipv6/resource_reserved_ipv6_assignment.go index 08663b141..9cadfb086 100644 --- a/digitalocean/reservedipv6/resource_reserved_ipv6_assignment.go +++ b/digitalocean/reservedipv6/resource_reserved_ipv6_assignment.go @@ -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, @@ -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) } @@ -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) diff --git a/digitalocean/reservedipv6/resource_reserved_ipv6_assignment_test.go b/digitalocean/reservedipv6/resource_reserved_ipv6_assignment_test.go index 057c75b3b..fab804c09 100644 --- a/digitalocean/reservedipv6/resource_reserved_ipv6_assignment_test.go +++ b/digitalocean/reservedipv6/resource_reserved_ipv6_assignment_test.go @@ -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]+")), ), @@ -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]+")), ), @@ -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)), ), }, }, @@ -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]+")), ), @@ -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]+")), ), @@ -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 } @@ -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" { @@ -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" { @@ -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 { @@ -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 { diff --git a/digitalocean/reservedipv6/resource_reserved_ipv6_test.go b/digitalocean/reservedipv6/resource_reserved_ipv6_test.go index ca024c363..cb8f826e0 100644 --- a/digitalocean/reservedipv6/resource_reserved_ipv6_test.go +++ b/digitalocean/reservedipv6/resource_reserved_ipv6_test.go @@ -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) }, @@ -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" { @@ -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" {