Skip to content

Commit 53fd239

Browse files
authored
tests(vpc): add a retry to give attached resources some time to delete (#2215)
1 parent 1df2fd0 commit 53fd239

File tree

3 files changed

+729
-714
lines changed

3 files changed

+729
-714
lines changed

scaleway/helpers_vpc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net"
77
"strconv"
88
"strings"
9+
"time"
910

1011
"github.com/hashicorp/go-cty/cty"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -14,6 +15,8 @@ import (
1415
validator "github.com/scaleway/scaleway-sdk-go/validation"
1516
)
1617

18+
const defaultVPCPrivateNetworkRetryInterval = 30 * time.Second
19+
1720
// vpcAPIWithRegion returns a new VPC API and the region for a Create request
1821
func vpcAPIWithRegion(d *schema.ResourceData, m interface{}) (*vpc.API, scw.Region, error) {
1922
meta := m.(*Meta)

scaleway/resource_vpc_private_network.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55

66
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
910
"github.com/scaleway/scaleway-sdk-go/api/vpc/v2"
@@ -284,18 +285,23 @@ func resourceScalewayVPCPrivateNetworkDelete(ctx context.Context, d *schema.Reso
284285
return diag.FromErr(err)
285286
}
286287

287-
var warnings diag.Diagnostics
288-
err = vpcAPI.DeletePrivateNetwork(&vpc.DeletePrivateNetworkRequest{
289-
PrivateNetworkID: ID,
290-
Region: region,
291-
}, scw.WithContext(ctx))
292-
if err != nil {
293-
if is404Error(err) {
294-
return append(warnings, diag.Diagnostic{
295-
Severity: diag.Warning,
296-
Summary: err.Error(),
297-
})
288+
err = retry.RetryContext(ctx, defaultVPCPrivateNetworkRetryInterval, func() *retry.RetryError {
289+
err := vpcAPI.DeletePrivateNetwork(&vpc.DeletePrivateNetworkRequest{
290+
PrivateNetworkID: ID,
291+
Region: region,
292+
}, scw.WithContext(ctx))
293+
if err != nil {
294+
if is412Error(err) {
295+
return retry.RetryableError(err)
296+
} else if !is404Error(err) {
297+
return retry.NonRetryableError(err)
298+
}
298299
}
300+
301+
return nil
302+
})
303+
304+
if err != nil {
299305
return diag.FromErr(err)
300306
}
301307

scaleway/testdata/vpc-public-gateway-dhcp-entry-basic.cassette.yaml

Lines changed: 709 additions & 703 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)