Skip to content

Commit a58f10b

Browse files
authored
fix(block): ignore inaccessible legacy snapshot in diff (#3258)
* fix(block): ignore inaccessible legacy snapshot in diff * fix(block): remove forceNew to add customdiff * set snapshot_id to null if legagcy one * remove dev.tfrc * update cassettes export-to-s3 * update cassettes * fix forceNew add Locality to customDiff * fix forceNew add Locality to customDiff * Delete tests/dev.tfrc
1 parent a2dbf63 commit a58f10b

File tree

6 files changed

+2866
-2731
lines changed

6 files changed

+2866
-2731
lines changed

internal/services/block/helpers_block.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ 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"
14+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
1315
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
1416
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
1517
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers"
@@ -56,6 +58,32 @@ func customDiffCannotShrink(key string) schema.CustomizeDiffFunc {
5658
})
5759
}
5860

61+
func customDiffSnapshot(key string) schema.CustomizeDiffFunc {
62+
return func(ctx context.Context, diff *schema.ResourceDiff, i any) error {
63+
if !diff.HasChange(key) {
64+
return nil
65+
}
66+
67+
oldValue, newValue := diff.GetChange(key)
68+
if dsf.Locality(key, oldValue.(string), newValue.(string), nil) {
69+
return nil
70+
}
71+
72+
blockAPI := block.NewAPI(meta.ExtractScwClient(i))
73+
zone, id, _ := locality.ParseLocalizedID(oldValue.(string))
74+
75+
_, err := blockAPI.GetSnapshot(&block.GetSnapshotRequest{
76+
SnapshotID: id,
77+
Zone: scw.Zone(zone),
78+
})
79+
if (httperrors.Is403(err) || httperrors.Is404(err)) && newValue == "" {
80+
return nil
81+
}
82+
83+
return diff.ForceNew(key)
84+
}
85+
}
86+
5987
func migrateInstanceToBlockVolume(ctx context.Context, api *instancehelpers.BlockAndInstanceAPI, zone scw.Zone, volumeID string, timeout time.Duration) (*block.Volume, error) {
6088
instanceVolumeResp, err := api.GetVolume(&instance.GetVolumeRequest{
6189
Zone: zone,

0 commit comments

Comments
 (0)