Skip to content

Commit 0af2be2

Browse files
committed
fix forceNew add Locality to customDiff
1 parent 827d627 commit 0af2be2

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

internal/services/block/helpers_block.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
1010
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
1111
"github.com/scaleway/scaleway-sdk-go/scw"
12+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/dsf"
1213
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
1314
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
1415
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
@@ -63,6 +64,10 @@ func customDiffSnapshot(key string) schema.CustomizeDiffFunc {
6364
}
6465

6566
oldValue, newValue := diff.GetChange(key)
67+
if dsf.Locality(key, oldValue.(string), newValue.(string), nil) {
68+
return nil
69+
}
70+
6671
blockAPI := block.NewAPI(meta.ExtractScwClient(i))
6772

6873
_, err := blockAPI.GetSnapshot(&block.GetSnapshotRequest{

internal/services/block/volume.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
99
block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
10+
"github.com/scaleway/scaleway-sdk-go/logger"
1011
"github.com/scaleway/scaleway-sdk-go/scw"
11-
"github.com/scaleway/terraform-provider-scaleway/v2/internal/dsf"
1212
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
1313
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
1414
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
@@ -52,11 +52,9 @@ func ResourceVolume() *schema.Resource {
5252
Description: "The volume size in GB",
5353
},
5454
"snapshot_id": {
55-
Type: schema.TypeString,
56-
Optional: true,
57-
ForceNew: true,
58-
Description: "The snapshot to create the volume from",
59-
DiffSuppressFunc: dsf.Locality,
55+
Type: schema.TypeString,
56+
Optional: true,
57+
Description: "The snapshot to create the volume from",
6058
},
6159
"instance_volume_id": {
6260
Type: schema.TypeString,
@@ -175,14 +173,14 @@ func ResourceBlockVolumeRead(ctx context.Context, d *schema.ResourceData, m any)
175173
snapshotID := ""
176174

177175
if volume.ParentSnapshotID != nil {
178-
id := *volume.ParentSnapshotID
176+
logger.Debugf("found snapshot In READ %s", volume.ParentSnapshotID)
179177
_, err := api.GetSnapshot(&block.GetSnapshotRequest{
180-
SnapshotID: id,
178+
SnapshotID: *volume.ParentSnapshotID,
181179
Zone: zone,
182180
})
183181

184-
if !httperrors.Is403(err) && !httperrors.Is404(err) {
185-
snapshotID = zonal.NewIDString(zone, id)
182+
if err == nil || (!httperrors.Is403(err) && !httperrors.Is404(err)) {
183+
snapshotID = zonal.NewIDString(zone, *volume.ParentSnapshotID)
186184
}
187185
}
188186

0 commit comments

Comments
 (0)