Skip to content

Commit 45bb0b8

Browse files
committed
fix(block): remove forceNew to add customdiff
1 parent 088fd4c commit 45bb0b8

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

internal/services/block/helpers_block.go

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

33
import (
44
"context"
5+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/logging"
56
"time"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
@@ -68,11 +69,16 @@ func customDiffSnapshot(key string) schema.CustomizeDiffFunc {
6869
_, err := blockAPI.GetSnapshot(&block.GetSnapshotRequest{
6970
SnapshotID: oldValue.(string),
7071
})
71-
if (httperrors.Is403(err) || httperrors.Is404(err)) && newValue == nil {
72+
logging.L.Debugf("customDiffSnapshot: old=%s, new=%s", oldValue, newValue)
73+
logging.L.Debugf("error: %v", err)
74+
75+
if httperrors.Is403(err) || httperrors.Is404(err) {
76+
logging.L.Infof("customDiffSnapshot: snapshot %s is missing or forbidden", oldValue)
7277
return nil
7378
}
7479

75-
return diff.ForceNew("snapshot_id")
80+
logging.L.Infof("customDiffSnapshot: forcing recreation due to snapshot_id change")
81+
return diff.ForceNew(key)
7682
}
7783
}
7884

internal/services/block/volume.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package block
22

33
import (
44
"context"
5-
65
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
76
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
87
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -201,6 +200,7 @@ func ResourceBlockVolumeUpdate(ctx context.Context, d *schema.ResourceData, m an
201200
req := &block.UpdateVolumeRequest{
202201
Zone: zone,
203202
VolumeID: volume.ID,
203+
Name: types.ExpandUpdatedStringPtr(volume.Name),
204204
}
205205

206206
if d.HasChange("name") {

tests/dev.tfrc

Whitespace-only changes.

0 commit comments

Comments
 (0)