diff --git a/equinix/data_source_metal_virtual_circuit.go b/equinix/data_source_metal_virtual_circuit.go index df5d290be..dafcfc110 100644 --- a/equinix/data_source_metal_virtual_circuit.go +++ b/equinix/data_source_metal_virtual_circuit.go @@ -1,12 +1,14 @@ package equinix import ( + "context" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceMetalVirtualCircuit() *schema.Resource { return &schema.Resource{ - Read: dataSourceMetalVirtualCircuitRead, + ReadContext: diagnosticsWrapper(dataSourceMetalVirtualCircuitRead), Schema: map[string]*schema.Schema{ "virtual_circuit_id": { @@ -112,8 +114,8 @@ func dataSourceMetalVirtualCircuit() *schema.Resource { } } -func dataSourceMetalVirtualCircuitRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceMetalVirtualCircuitRead(ctx context.Context, d *schema.ResourceData, meta interface{}) error { vcId := d.Get("virtual_circuit_id").(string) d.SetId(vcId) - return resourceMetalVirtualCircuitRead(d, meta) + return resourceMetalVirtualCircuitRead(ctx, d, meta) } diff --git a/equinix/resource_metal_virtual_circuit.go b/equinix/resource_metal_virtual_circuit.go index 9d24f7763..7d9ded70e 100644 --- a/equinix/resource_metal_virtual_circuit.go +++ b/equinix/resource_metal_virtual_circuit.go @@ -1,6 +1,7 @@ package equinix import ( + "context" "fmt" "log" "reflect" @@ -15,12 +16,12 @@ import ( func resourceMetalVirtualCircuit() *schema.Resource { return &schema.Resource{ - Read: resourceMetalVirtualCircuitRead, - Create: resourceMetalVirtualCircuitCreate, - Update: resourceMetalVirtualCircuitUpdate, - Delete: resourceMetalVirtualCircuitDelete, + ReadWithoutTimeout: diagnosticsWrapper(resourceMetalVirtualCircuitRead), + CreateContext: diagnosticsWrapper(resourceMetalVirtualCircuitCreate), + UpdateWithoutTimeout: diagnosticsWrapper(resourceMetalVirtualCircuitUpdate), + DeleteContext: diagnosticsWrapper(resourceMetalVirtualCircuitDelete), Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -137,7 +138,7 @@ func resourceMetalVirtualCircuit() *schema.Resource { } } -func resourceMetalVirtualCircuitCreate(d *schema.ResourceData, meta interface{}) error { +func resourceMetalVirtualCircuitCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) error { meta.(*Config).addModuleToMetalUserAgent(d) client := meta.(*Config).metal vncr := packngo.VCCreateRequest{ @@ -182,22 +183,22 @@ func resourceMetalVirtualCircuitCreate(d *schema.ResourceData, meta interface{}) createWaiter := getVCStateWaiter( client, vc.ID, - d.Timeout(schema.TimeoutCreate), + d.Timeout(schema.TimeoutCreate)-30*time.Second, []string{string(packngo.VCStatusActivating)}, []string{string(packngo.VCStatusActive)}, ) - _, err = createWaiter.WaitForState() + _, err = createWaiter.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for virtual circuit %s to be created: %s", vc.ID, err.Error()) } d.SetId(vc.ID) - return resourceMetalVirtualCircuitRead(d, meta) + return resourceMetalVirtualCircuitRead(ctx, d, meta) } -func resourceMetalVirtualCircuitRead(d *schema.ResourceData, meta interface{}) error { +func resourceMetalVirtualCircuitRead(ctx context.Context, d *schema.ResourceData, meta interface{}) error { meta.(*Config).addModuleToMetalUserAgent(d) client := meta.(*Config).metal vcId := d.Id() @@ -278,7 +279,7 @@ func getVCStateWaiter(client *packngo.Client, id string, timeout time.Duration, } } -func resourceMetalVirtualCircuitUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceMetalVirtualCircuitUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) error { meta.(*Config).addModuleToMetalUserAgent(d) client := meta.(*Config).metal @@ -323,10 +324,10 @@ func resourceMetalVirtualCircuitUpdate(d *schema.ResourceData, meta interface{}) return friendlyError(err) } } - return resourceMetalVirtualCircuitRead(d, meta) + return resourceMetalVirtualCircuitRead(ctx, d, meta) } -func resourceMetalVirtualCircuitDelete(d *schema.ResourceData, meta interface{}) error { +func resourceMetalVirtualCircuitDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) error { meta.(*Config).addModuleToMetalUserAgent(d) client := meta.(*Config).metal @@ -338,12 +339,12 @@ func resourceMetalVirtualCircuitDelete(d *schema.ResourceData, meta interface{}) deleteWaiter := getVCStateWaiter( client, d.Id(), - d.Timeout(schema.TimeoutDelete), + d.Timeout(schema.TimeoutDelete)-30*time.Second, []string{string(packngo.VCStatusDeleting)}, []string{}, ) - _, err = deleteWaiter.WaitForState() + _, err = deleteWaiter.WaitForStateContext(ctx) if ignoreResponseErrors(httpForbidden, httpNotFound)(nil, err) != nil { return fmt.Errorf("Error deleting virtual circuit %s: %s", d.Id(), err) } diff --git a/equinix/resource_metal_virtual_circuit_acc_test.go b/equinix/resource_metal_virtual_circuit_acc_test.go index 144b956fa..13a111734 100644 --- a/equinix/resource_metal_virtual_circuit_acc_test.go +++ b/equinix/resource_metal_virtual_circuit_acc_test.go @@ -123,7 +123,7 @@ func TestAccMetalVirtualCircuit_dedicated(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ // Error: Error waiting for virtual circuit 863d4df5-b3ea-46ee-8497-858cb0cbfcb9 to be created: GET https://api.equinix.com/metal/v1/virtual-circuits/863d4df5-b3ea-46ee-8497-858cb0cbfcb9?include=project%2Cport%2Cvirtual_network%2Cvrf: 500 Oh snap, something went wrong! We've logged the error and will take a look - please reach out to us if you continue having trouble. PreCheck: func() { testAccPreCheck(t) }, ExternalProviders: testExternalProviders, - Providers: testAccProviders, + ProviderFactories: testAccProviderFactories, CheckDestroy: testAccMetalVirtualCircuitCheckDestroyed, Steps: []resource.TestStep{ {