Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions internal/services/instance/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func ResourceInstanceSnapshotCreate(ctx context.Context, d *schema.ResourceData,
req.VolumeType = volumeType
}

diags := handleDeprecatedSnapshotVolumeType(d)
if diags.HasError() {
return diags
}

req.Tags = types.ExpandStringsPtr(d.Get("tags"))

if volumeID, volumeIDExist := d.GetOk("volume_id"); volumeIDExist {
Expand Down Expand Up @@ -181,22 +186,16 @@ func ResourceInstanceSnapshotRead(ctx context.Context, d *schema.ResourceData, m
return diag.FromErr(err)
}

diags := handleDeprecatedSnapshotVolumeType(d)
if diags.HasError() {
return diags
}

_ = d.Set("name", snapshot.Snapshot.Name)
_ = d.Set("created_at", snapshot.Snapshot.CreationDate.Format(time.RFC3339))
_ = d.Set("type", snapshot.Snapshot.VolumeType.String())
_ = d.Set("tags", snapshot.Snapshot.Tags)

if d.Get("type").(string) == instanceSDK.VolumeVolumeTypeBSSD.String() {
return diag.Diagnostics{
{
Severity: diag.Warning,
Summary: "Snapshot type `b_ssd` is deprecated",
Detail: "If you want to migrate existing snapshots, you can visit `https://www.scaleway.com/en/docs/instances/how-to/migrate-volumes-snapshots-to-sbs/` for more information.",
AttributePath: cty.GetAttrPath("type"),
},
}
}

return nil
}

Expand Down Expand Up @@ -256,3 +255,29 @@ func ResourceInstanceSnapshotDelete(ctx context.Context, d *schema.ResourceData,

return nil
}

func handleDeprecatedSnapshotVolumeType(d *schema.ResourceData) diag.Diagnostics {
if d.Get("type").(string) == instanceSDK.SnapshotVolumeTypeBSSD.String() {
return diag.Diagnostics{
{
Severity: diag.Warning,
Summary: "Snapshot type `b_ssd` is deprecated",
Detail: "If you want to migrate existing snapshots, you can visit `https://www.scaleway.com/en/docs/instances/how-to/migrate-volumes-snapshots-to-sbs/` for more information.",
AttributePath: cty.GetAttrPath("type"),
},
}
}

if d.Get("type").(string) == instanceSDK.SnapshotVolumeTypeUnified.String() {
return diag.Diagnostics{
{
Severity: diag.Warning,
Summary: "Snapshot type `unified` is deprecated",
Detail: "If you want to migrate existing snapshots, you can visit `https://www.scaleway.com/en/docs/instances/how-to/migrate-volumes-snapshots-to-sbs/` for more information.",
AttributePath: cty.GetAttrPath("type"),
},
}
}

return diag.Diagnostics{}
}
200 changes: 0 additions & 200 deletions internal/services/instance/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,6 @@ import (
instancechecks "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/testfuncs"
)

func TestAccSnapshot_BlockVolume(t *testing.T) {
t.Skip("Resource \"scaleway_instance_snapshot\" is depracated for block volumes")

tt := acctest.NewTestTools(t)
defer tt.Cleanup()
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: instancechecks.IsVolumeDestroyed(tt),
Steps: []resource.TestStep{
{
Config: `
resource "scaleway_instance_volume" "main" {
type = "b_ssd"
size_in_gb = 20
}

resource "scaleway_instance_snapshot" "main" {
volume_id = scaleway_instance_volume.main.id
}`,
Check: resource.ComposeTestCheckFunc(
isSnapshotPresent(tt, "scaleway_instance_snapshot.main"),
),
},
},
})
}

func TestAccSnapshot_Unified(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: instancechecks.IsVolumeDestroyed(tt),
Steps: []resource.TestStep{
{
Config: `
resource "scaleway_instance_volume" "main" {
type = "l_ssd"
size_in_gb = 10
}

resource "scaleway_instance_server" "main" {
image = "ubuntu_jammy"
type = "DEV1-S"
root_volume {
size_in_gb = 10
volume_type = "l_ssd"
}
additional_volume_ids = [
scaleway_instance_volume.main.id
]
}

resource "scaleway_instance_snapshot" "main" {
volume_id = scaleway_instance_volume.main.id
type = "unified"
depends_on = [scaleway_instance_server.main]
}
`,
Check: resource.ComposeTestCheckFunc(
isSnapshotPresent(tt, "scaleway_instance_snapshot.main"),
resource.TestCheckResourceAttr("scaleway_instance_snapshot.main", "type", "unified"),
),
},
},
})
}

func TestAccSnapshot_Server(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()
Expand Down Expand Up @@ -112,136 +42,6 @@ func TestAccSnapshot_Server(t *testing.T) {
})
}

func TestAccSnapshot_ServerWithBlockVolume(t *testing.T) {
t.Skip("Resource \"scaleway_instance_snapshot\" is depracated for block volumes")

tt := acctest.NewTestTools(t)
defer tt.Cleanup()
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: resource.ComposeTestCheckFunc(
instancechecks.IsVolumeDestroyed(tt),
instancechecks.IsServerDestroyed(tt),
isSnapshotDestroyed(tt),
),
Steps: []resource.TestStep{
{
Config: `
resource "scaleway_instance_volume" main {
type = "b_ssd"
size_in_gb = 10
}

resource "scaleway_instance_server" main {
image = "ubuntu_focal"
type = "DEV1-S"
root_volume {
size_in_gb = 10
volume_type = "l_ssd"
}
additional_volume_ids = [
scaleway_instance_volume.main.id
]
}

resource "scaleway_instance_snapshot" main {
volume_id = scaleway_instance_volume.main.id
}`,
Check: resource.ComposeTestCheckFunc(
isSnapshotPresent(tt, "scaleway_instance_snapshot.main"),
),
},
},
})
}

func TestAccSnapshot_RenameSnapshot(t *testing.T) {
t.Skip("Resource \"scaleway_instance_snapshot\" is depracated for block volumes")

tt := acctest.NewTestTools(t)
defer tt.Cleanup()
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: instancechecks.IsVolumeDestroyed(tt),
Steps: []resource.TestStep{
{
Config: `
resource "scaleway_instance_volume" "main" {
type = "b_ssd"
size_in_gb = 20
}

resource "scaleway_instance_snapshot" "main" {
volume_id = scaleway_instance_volume.main.id
name = "first_name"
tags = ["test-terraform"]
}`,
Check: resource.ComposeTestCheckFunc(
isSnapshotPresent(tt, "scaleway_instance_snapshot.main"),
resource.TestCheckResourceAttr("scaleway_instance_snapshot.main", "tags.0", "test-terraform"),
),
},
{
Config: `
resource "scaleway_instance_volume" "main" {
type = "b_ssd"
size_in_gb = 20
}

resource "scaleway_instance_snapshot" "main" {
volume_id = scaleway_instance_volume.main.id
name = "second_name"
}`,
Check: resource.ComposeTestCheckFunc(
isSnapshotPresent(tt, "scaleway_instance_snapshot.main"),
resource.TestCheckResourceAttr("scaleway_instance_snapshot.main", "tags.#", "0"),
),
},
},
})
}

func TestAccSnapshot_FromObject(t *testing.T) {
t.Skip("Resource \"scaleway_instance_snapshot\" is depracated")
// TestAccSnapshot_FromS3 tests the same logic on the scaleway_block_snapshot resource

tt := acctest.NewTestTools(t)
defer tt.Cleanup()
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: instancechecks.IsVolumeDestroyed(tt),
Steps: []resource.TestStep{
{
Config: `
resource "scaleway_object_bucket" "bucket" {
name = "test-instance-snapshot-import-from-object"
}

resource "scaleway_object" "image" {
bucket = scaleway_object_bucket.bucket.name
key = "image.qcow"
file = "testfixture/empty.qcow2"
}

resource "scaleway_block_snapshot" "snapshot" {
name = "test-instance-snapshot-import-from-object"
type = "b_ssd"
import {
bucket = scaleway_object.image.bucket
key = scaleway_object.image.key
}
}`,
Check: resource.ComposeTestCheckFunc(
isSnapshotPresent(tt, "scaleway_instance_snapshot.snapshot"),
),
},
},
})
}

func isSnapshotPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down
Loading
Loading