Skip to content

Commit

Permalink
feat(block_volume): support migration from instance volume
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax committed Feb 14, 2025
1 parent 7442f90 commit 8dfb0dd
Show file tree
Hide file tree
Showing 4 changed files with 1,501 additions and 24 deletions.
41 changes: 41 additions & 0 deletions internal/services/block/helpers_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"

Check failure on line 9 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tfproviderlint

could not import github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1 (no metadata for github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1)
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"

Check failure on line 10 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tfproviderlint

could not import github.com/scaleway/scaleway-sdk-go/api/instance/v1 (no metadata for github.com/scaleway/scaleway-sdk-go/api/instance/v1)
"github.com/scaleway/scaleway-sdk-go/scw"

Check failure on line 11 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tfproviderlint

could not import github.com/scaleway/scaleway-sdk-go/scw (no metadata for github.com/scaleway/scaleway-sdk-go/scw)
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"

Check failure on line 12 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tfproviderlint

could not import github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors (no metadata for github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors)
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"

Check failure on line 13 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tfproviderlint

could not import github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal (no metadata for github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal)
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers"

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (domain)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (flexibleip)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (applesilicon)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (function)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (baremetal)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (az)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (account)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (cockpit)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (block)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (iam)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (billing)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / test-scwconfig

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (inference)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (container)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (instance)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (k8s)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (lb)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (mnq)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (object)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (rdb)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (registry)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (iot)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (ipam)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (secret)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (tem)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (jobs)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (marketplace)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (mongodb)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (redis)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (sdb)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tfproviderlint

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (vpcgw)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (webhosting)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:

Check failure on line 15 in internal/services/block/helpers_block.go

View workflow job for this annotation

GitHub Actions / tests (vpc)

no required module provides package github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/instancehelpers; to add it:
)

const (
Expand Down Expand Up @@ -53,3 +55,42 @@ func customDiffCannotShrink(key string) schema.CustomizeDiffFunc {
return oldValue < newValue
})
}

func migrateInstanceToBlockVolume(ctx context.Context, api *instancehelpers.BlockAndInstanceAPI, zone scw.Zone, volumeID string, timeout time.Duration) (*block.Volume, error) {
instanceVolumeResp, err := api.GetVolume(&instance.GetVolumeRequest{
Zone: zone,
VolumeID: volumeID,
})
if err != nil {
return nil, err
}

plan, err := api.PlanBlockMigration(&instance.PlanBlockMigrationRequest{
Zone: instanceVolumeResp.Volume.Zone,
VolumeID: &instanceVolumeResp.Volume.ID,
})
if err != nil {
return nil, err
}

err = api.ApplyBlockMigration(&instance.ApplyBlockMigrationRequest{
Zone: instanceVolumeResp.Volume.Zone,
VolumeID: &instanceVolumeResp.Volume.ID,
ValidationKey: plan.ValidationKey,
})
if err != nil {
return nil, err
}

_, err = instancehelpers.WaitForVolume(ctx, api.API, zone, volumeID, timeout)
if err != nil && !httperrors.Is404(err) {
return nil, err
}

blockVolume, err := waitForBlockVolume(ctx, api.BlockAPI, zone, volumeID, timeout)
if err != nil {
return nil, err
}

return blockVolume, nil
}
Loading

0 comments on commit 8dfb0dd

Please sign in to comment.