@@ -9,8 +9,10 @@ import (
9
9
block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
10
10
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
11
11
"github.com/scaleway/scaleway-sdk-go/scw"
12
+ "github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
12
13
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
13
14
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
15
+ "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers"
14
16
)
15
17
16
18
const (
@@ -53,3 +55,42 @@ func customDiffCannotShrink(key string) schema.CustomizeDiffFunc {
53
55
return oldValue < newValue
54
56
})
55
57
}
58
+
59
+ func migrateInstanceToBlockVolume (ctx context.Context , api * instancehelpers.BlockAndInstanceAPI , zone scw.Zone , volumeID string , timeout time.Duration ) (* block.Volume , error ) {
60
+ instanceVolumeResp , err := api .GetVolume (& instance.GetVolumeRequest {
61
+ Zone : zone ,
62
+ VolumeID : volumeID ,
63
+ })
64
+ if err != nil {
65
+ return nil , err
66
+ }
67
+
68
+ plan , err := api .PlanBlockMigration (& instance.PlanBlockMigrationRequest {
69
+ Zone : instanceVolumeResp .Volume .Zone ,
70
+ VolumeID : & instanceVolumeResp .Volume .ID ,
71
+ })
72
+ if err != nil {
73
+ return nil , err
74
+ }
75
+
76
+ err = api .ApplyBlockMigration (& instance.ApplyBlockMigrationRequest {
77
+ Zone : instanceVolumeResp .Volume .Zone ,
78
+ VolumeID : & instanceVolumeResp .Volume .ID ,
79
+ ValidationKey : plan .ValidationKey ,
80
+ })
81
+ if err != nil {
82
+ return nil , err
83
+ }
84
+
85
+ _ , err = instancehelpers .WaitForVolume (ctx , api .API , zone , volumeID , timeout )
86
+ if err != nil && ! httperrors .Is404 (err ) {
87
+ return nil , err
88
+ }
89
+
90
+ blockVolume , err := waitForBlockVolume (ctx , api .BlockAPI , zone , volumeID , timeout )
91
+ if err != nil {
92
+ return nil , err
93
+ }
94
+
95
+ return blockVolume , nil
96
+ }
0 commit comments