Skip to content

Commit 133248b

Browse files
committed
fix(block): ignore inaccessible legacy snapshot in diff
1 parent a2dbf63 commit 133248b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

internal/services/block/helpers_block.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ func customDiffCannotShrink(key string) schema.CustomizeDiffFunc {
5656
})
5757
}
5858

59+
func customDiffSnapshot(key string) schema.CustomizeDiffFunc {
60+
return func(ctx context.Context, diff *schema.ResourceDiff, i any) error {
61+
if !diff.HasChange(key) {
62+
return nil
63+
}
64+
oldValue, newValue := diff.GetChange(key)
65+
blockAPI := block.NewAPI(meta.ExtractScwClient(i))
66+
_, err := blockAPI.GetSnapshot(&block.GetSnapshotRequest{
67+
SnapshotID: oldValue.(string),
68+
})
69+
if (httperrors.Is403(err) || httperrors.Is404(err)) && newValue == nil {
70+
return nil
71+
}
72+
73+
return diff.ForceNew("snapshot_id")
74+
}
75+
}
76+
5977
func migrateInstanceToBlockVolume(ctx context.Context, api *instancehelpers.BlockAndInstanceAPI, zone scw.Zone, volumeID string, timeout time.Duration) (*block.Volume, error) {
6078
instanceVolumeResp, err := api.GetVolume(&instance.GetVolumeRequest{
6179
Zone: zone,

internal/services/block/volume.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func ResourceVolume() *schema.Resource {
5454
"snapshot_id": {
5555
Type: schema.TypeString,
5656
Optional: true,
57-
ForceNew: true,
5857
Description: "The snapshot to create the volume from",
5958
DiffSuppressFunc: dsf.Locality,
6059
},
@@ -79,6 +78,7 @@ func ResourceVolume() *schema.Resource {
7978
},
8079
CustomizeDiff: customdiff.All(
8180
customDiffCannotShrink("size_in_gb"),
81+
customDiffSnapshot("snapshot_id"),
8282
),
8383
}
8484
}

0 commit comments

Comments
 (0)