Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #217 from equinix/fix_wait_for_deprovision_destroy
Browse files Browse the repository at this point in the history
include device filter in hwReservationStateRefreshFunc
  • Loading branch information
displague authored Mar 14, 2022
2 parents 8191e1a + 8e8f832 commit c8e9ca6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions metal/helpers_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const (

func hwReservationStateRefreshFunc(client *packngo.Client, reservationId, instanceId string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
r, _, err := client.HardwareReservations.Get(reservationId, nil)
r, _, err := client.HardwareReservations.Get(reservationId, &packngo.GetOptions{Includes: []string{"device"}})
state := deprovisioning
switch {
case err != nil:
Expand Down Expand Up @@ -224,14 +224,14 @@ func powerOnAndWait(d *schema.ResourceData, meta interface{}) error {
}
state := d.Get("state").(string)
if state != "active" {
return friendlyError(fmt.Errorf("Device in non-active state \"%s\"", state))
return friendlyError(fmt.Errorf("device in non-active state \"%s\"", state))
}
return nil
}

func validateFacilityForDevice(v interface{}, k string) (ws []string, errors []error) {
if v.(string) == "any" {
errors = append(errors, fmt.Errorf(`Cannot use facility: "any"`))
errors = append(errors, fmt.Errorf(`cannot use facility: "any"`))
}
return
}
Expand Down
17 changes: 12 additions & 5 deletions metal/helpers_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ func Test_waitUntilReservationProvisionable(t *testing.T) {
}

return &mockHWService{
GetFn: func(_ string, _ *packngo.GetOptions) (*packngo.HardwareReservation, *packngo.Response, error) {
GetFn: func(_ string, opts *packngo.GetOptions) (*packngo.HardwareReservation, *packngo.Response, error) {
response := responses[*invoked]
*invoked++

var device *packngo.Device
if opts != nil && contains(opts.Includes, "device") {
device = &packngo.Device{ID: response.id}
}
return &packngo.HardwareReservation{
Device: &packngo.Device{ID: response.id}, Provisionable: response.provisionable,
Device: device, Provisionable: response.provisionable,
}, nil, nil
},
}
Expand All @@ -102,12 +106,16 @@ func Test_waitUntilReservationProvisionable(t *testing.T) {
invoked := new(int)

return &mockHWService{
GetFn: func(_ string, _ *packngo.GetOptions) (*packngo.HardwareReservation, *packngo.Response, error) {
GetFn: func(_ string, opts *packngo.GetOptions) (*packngo.HardwareReservation, *packngo.Response, error) {
response := responses[*invoked]
*invoked++

var device *packngo.Device
if opts != nil && contains(opts.Includes, "device") {
device = &packngo.Device{ID: response.id}
}
return &packngo.HardwareReservation{
Device: &packngo.Device{ID: response.id}, Provisionable: response.provisionable,
Device: device, Provisionable: response.provisionable,
}, nil, nil
},
}
Expand All @@ -127,7 +135,6 @@ func Test_waitUntilReservationProvisionable(t *testing.T) {
return &packngo.HardwareReservation{
Device: nil, Provisionable: false,
}, nil, nil

},
},
},
Expand Down

0 comments on commit c8e9ca6

Please sign in to comment.