From 25962b20f493d71c3dd8486b055edc10251849ee Mon Sep 17 00:00:00 2001 From: Charles Treatman Date: Tue, 1 Oct 2024 13:56:53 -0500 Subject: [PATCH] remove workaround from test since we don't need it any more --- .../resources/metal/device/resource_test.go | 49 +------------------ 1 file changed, 2 insertions(+), 47 deletions(-) diff --git a/internal/resources/metal/device/resource_test.go b/internal/resources/metal/device/resource_test.go index 15b55cda3..2295f954d 100644 --- a/internal/resources/metal/device/resource_test.go +++ b/internal/resources/metal/device/resource_test.go @@ -9,7 +9,6 @@ import ( "net/http/httptest" "regexp" "testing" - "time" "github.com/equinix/terraform-provider-equinix/internal/acceptance" "github.com/equinix/terraform-provider-equinix/internal/config" @@ -914,43 +913,8 @@ resource "equinix_metal_device" "test" { `, acceptance.ConfAccMetalDevice_base(acceptance.Preferable_plans, acceptance.Preferable_metros, acceptance.Preferable_os), projSuffix, acceptance.TestDeviceTerminationTime(), updateTimeout) } -func testAccWaitForMetalDeviceActive(project, deviceHostName string) resource.ImportStateIdFunc { - return func(state *terraform.State) (string, error) { - defaultTimeout := 20 * time.Minute - - rs, ok := state.RootModule().Resources[project] - if !ok { - return "", fmt.Errorf("Project Not found in the state: %s", project) - } - if rs.Primary.ID == "" { - return "", fmt.Errorf("No Record ID is set") - } - - meta := acceptance.TestAccProvider.Meta() - rd := new(schema.ResourceData) - client := meta.(*config.Config).NewMetalClientForTesting() - resp, _, err := client.DevicesApi.FindProjectDevices(context.TODO(), rs.Primary.ID).Search(deviceHostName).Execute() - if err != nil { - return "", fmt.Errorf("error while fetching devices for project [%s], error: %w", rs.Primary.ID, err) - } - devices := resp.Devices - if len(devices) == 0 { - return "", fmt.Errorf("Not able to find devices in project [%s]", rs.Primary.ID) - } - if len(devices) > 1 { - return "", fmt.Errorf("Found more than one device with the hostname in project [%s]", rs.Primary.ID) - } - - rd.SetId(devices[0].GetId()) - return devices[0].GetId(), device.WaitForActiveDevice(context.Background(), rd, acceptance.TestAccProvider.Meta(), defaultTimeout) - } -} - func TestAccMetalDeviceCreate_timeout(t *testing.T) { rs := acctest.RandString(10) - r := "equinix_metal_device.test" - hostname := "tfacc-test-device" - project := "equinix_metal_project.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, @@ -963,17 +927,8 @@ func TestAccMetalDeviceCreate_timeout(t *testing.T) { ExpectError: matchErrDeviceReadyTimeout, }, { - /** - Step 1 errors out, state doesnt have device, need to import that in the state before deleting - */ - ResourceName: r, - ImportState: true, - ImportStateIdFunc: testAccWaitForMetalDeviceActive(project, hostname), - ImportStatePersist: true, - }, - { - Config: testAccMetalDeviceConfig_timeout(rs, "", "", ""), - Destroy: true, + // Allow the device to reach ready state so it can be destroyed after test + Config: testAccMetalDeviceConfig_timeout(rs, "", "", ""), }, }, })