Skip to content

Commit 088fd4c

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

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

internal/services/block/helpers_block.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ 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+
65+
oldValue, newValue := diff.GetChange(key)
66+
blockAPI := block.NewAPI(meta.ExtractScwClient(i))
67+
68+
_, err := blockAPI.GetSnapshot(&block.GetSnapshotRequest{
69+
SnapshotID: oldValue.(string),
70+
})
71+
if (httperrors.Is403(err) || httperrors.Is404(err)) && newValue == nil {
72+
return nil
73+
}
74+
75+
return diff.ForceNew("snapshot_id")
76+
}
77+
}
78+
5979
func migrateInstanceToBlockVolume(ctx context.Context, api *instancehelpers.BlockAndInstanceAPI, zone scw.Zone, volumeID string, timeout time.Duration) (*block.Volume, error) {
6080
instanceVolumeResp, err := api.GetVolume(&instance.GetVolumeRequest{
6181
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)