Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Timeout for metal virtual circuits #380

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions equinix/data_source_metal_virtual_circuit.go
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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)
}
31 changes: 16 additions & 15 deletions equinix/resource_metal_virtual_circuit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package equinix

import (
"context"
"fmt"
"log"
"reflect"
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion equinix/resource_metal_virtual_circuit_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down