Skip to content

Commit 09a924a

Browse files
authored
fix(block_volume): wait for status available before deletion (#2931)
1 parent 7ea0db6 commit 09a924a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

internal/services/block/volume.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func ResourceBlockVolumeDelete(ctx context.Context, d *schema.ResourceData, m in
227227
return diag.FromErr(err)
228228
}
229229

230-
_, err = waitForBlockVolume(ctx, api, zone, id, d.Timeout(schema.TimeoutDelete))
230+
_, err = waitForBlockVolumeToBeAvailable(ctx, api, zone, id, d.Timeout(schema.TimeoutDelete))
231231
if err != nil {
232232
if httperrors.Is404(err) {
233233
d.SetId("")

internal/services/block/waiters.go

+19
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ func waitForBlockVolume(ctx context.Context, blockAPI *block.API, zone scw.Zone,
2525
return volume, err
2626
}
2727

28+
func waitForBlockVolumeToBeAvailable(ctx context.Context, blockAPI *block.API, zone scw.Zone, id string, timeout time.Duration) (*block.Volume, error) {
29+
retryInterval := defaultBlockRetryInterval
30+
if transport.DefaultWaitRetryInterval != nil {
31+
retryInterval = *transport.DefaultWaitRetryInterval
32+
}
33+
34+
terminalStatus := block.VolumeStatusAvailable
35+
volume, err := blockAPI.WaitForVolumeAndReferences(&block.WaitForVolumeAndReferencesRequest{
36+
Zone: zone,
37+
VolumeID: id,
38+
RetryInterval: &retryInterval,
39+
Timeout: scw.TimeDurationPtr(timeout),
40+
41+
VolumeTerminalStatus: &terminalStatus,
42+
}, scw.WithContext(ctx))
43+
44+
return volume, err
45+
}
46+
2847
func waitForBlockSnapshot(ctx context.Context, blockAPI *block.API, zone scw.Zone, id string, timeout time.Duration) (*block.Snapshot, error) {
2948
retryInterval := defaultBlockRetryInterval
3049
if transport.DefaultWaitRetryInterval != nil {

0 commit comments

Comments
 (0)