Skip to content

Commit f695db0

Browse files
committed
set snapshot_id to null if legagcy one
1 parent 6dbc43c commit f695db0

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

internal/services/block/helpers_block.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package block
22

33
import (
44
"context"
5-
"github.com/scaleway/terraform-provider-scaleway/v2/internal/logging"
65
"time"
76

87
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
@@ -69,15 +68,9 @@ func customDiffSnapshot(key string) schema.CustomizeDiffFunc {
6968
_, err := blockAPI.GetSnapshot(&block.GetSnapshotRequest{
7069
SnapshotID: oldValue.(string),
7170
})
72-
logging.L.Debugf("customDiffSnapshot: old=%s, new=%s", oldValue, newValue)
73-
logging.L.Debugf("error: %v", err)
74-
7571
if (httperrors.Is403(err) || httperrors.Is404(err)) && newValue == "" {
76-
logging.L.Infof("customDiffSnapshot: snapshot %s is missing or forbidden", oldValue)
7772
return nil
7873
}
79-
80-
logging.L.Infof("customDiffSnapshot: forcing recreation due to snapshot_id change")
8174
return diff.ForceNew(key)
8275
}
8376
}

internal/services/block/volume.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func ResourceVolume() *schema.Resource {
5353
"snapshot_id": {
5454
Type: schema.TypeString,
5555
Optional: true,
56+
ForceNew: true,
5657
Description: "The snapshot to create the volume from",
5758
DiffSuppressFunc: dsf.Locality,
5859
},
@@ -76,8 +77,8 @@ func ResourceVolume() *schema.Resource {
7677
"project_id": account.ProjectIDSchema(),
7778
},
7879
CustomizeDiff: customdiff.All(
79-
customDiffCannotShrink("size_in_gb"),
8080
customDiffSnapshot("snapshot_id"),
81+
customDiffCannotShrink("size_in_gb"),
8182
),
8283
}
8384
}
@@ -170,8 +171,11 @@ func ResourceBlockVolumeRead(ctx context.Context, d *schema.ResourceData, m any)
170171
_ = d.Set("zone", volume.Zone)
171172
_ = d.Set("project_id", volume.ProjectID)
172173
_ = d.Set("tags", volume.Tags)
173-
174-
if volume.ParentSnapshotID != nil {
174+
_, err = api.GetSnapshot(&block.GetSnapshotRequest{
175+
SnapshotID: *volume.ParentSnapshotID,
176+
Zone: zone,
177+
})
178+
if volume.ParentSnapshotID != nil && !httperrors.Is403(err) && !httperrors.Is404(err) {
175179
_ = d.Set("snapshot_id", zonal.NewIDString(zone, *volume.ParentSnapshotID))
176180
} else {
177181
_ = d.Set("snapshot_id", "")

0 commit comments

Comments
 (0)