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
7 changes: 2 additions & 5 deletions docs/resources/instance_snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ resource "scaleway_instance_server" "main" {

resource "scaleway_instance_snapshot" "main" {
volume_id = scaleway_instance_volume.main.id
type = "unified"
depends_on = [scaleway_instance_server.main]
}
```
Expand All @@ -59,7 +58,6 @@ resource "scaleway_object" "qcow" {
}

resource "scaleway_instance_snapshot" "snapshot" {
type = "unified"
import {
bucket = scaleway_object.qcow.bucket
key = scaleway_object.qcow.key
Expand All @@ -72,11 +70,12 @@ resource "scaleway_instance_snapshot" "snapshot" {
The following arguments are supported:

- `volume_id` - (Optional) The ID of the volume to take a snapshot from.
- `type` - (Optional) The snapshot's volume type. The possible values are: `l_ssd` (Local SSD) and `unified`.
- `type` - (Default to `l_ssd`) The snapshot's volume type. The possible values are: `l_ssd` (Local SSD).
Updates to this field will recreate a new resource.

~> **Important:** Snapshots of volumes with type `b_ssd` (Block SSD) are deprecated and cannot be managed using the `scaleway_instance_snapshot` resource anymore. Please use the `scaleway_block_snapshot` resource instead.
If you want to migrate existing snapshots, you can visit [this page](https://www.scaleway.com/en/docs/instances/how-to/migrate-volumes-snapshots-to-sbs/) for more information.
~> **Important:** Snapshots of volumes with type `unified` (can be used with both Block and Local SSD) are deprecated since the migration to SBS.

- `name` - (Optional) The name of the snapshot. If not provided it will be randomly generated.
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which
Expand All @@ -88,8 +87,6 @@ If you want to migrate existing snapshots, you can visit [this page](https://www
- `bucket` - Bucket name containing [qcow2](https://en.wikipedia.org/wiki/Qcow) to import
- `key` - Key of the object to import

-> **Note:** The type `unified` could be instantiated on both `l_ssd` and `b_ssd` volumes.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down
4 changes: 4 additions & 0 deletions internal/services/instance/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func ResourceInstanceSnapshotCreate(ctx context.Context, d *schema.ResourceData,
}

if _, isImported := d.GetOk("import"); isImported {
if req.VolumeType == "" {
req.VolumeType = instanceSDK.SnapshotVolumeTypeLSSD
}

req.Bucket = types.ExpandStringPtr(regional.ExpandID(d.Get("import.0.bucket")).ID)
req.Key = types.ExpandStringPtr(d.Get("import.0.key"))
}
Expand Down
75 changes: 75 additions & 0 deletions internal/services/instance/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"fmt"
"testing"

sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
instanceSDK "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance"
instancechecks "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/testfuncs"
objectchecks "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/object/testfuncs"
)

func TestAccSnapshot_Server(t *testing.T) {
Expand Down Expand Up @@ -42,6 +44,79 @@ func TestAccSnapshot_Server(t *testing.T) {
})
}

func TestAccSnapshot_FromS3(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()

bucketName := sdkacctest.RandomWithPrefix("test-acc-scaleway-instance-snapshot")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: resource.ComposeTestCheckFunc(
isSnapshotDestroyed(tt),
objectchecks.IsObjectDestroyed(tt),
objectchecks.IsBucketDestroyed(tt),
),
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "scaleway_object_bucket" "snapshot-bucket" {
name = "%s"
}

resource "scaleway_object" "qcow-object" {
bucket = scaleway_object_bucket.snapshot-bucket.name
key = "test-acc-instance-snapshot.qcow2"
file = "testfixture/small_image.qcow2"
}

resource "scaleway_instance_snapshot" "qcow-instance-snapshot" {
name = "test-acc-snapshot-import-default"
import {
bucket = scaleway_object.qcow-object.bucket
key = scaleway_object.qcow-object.key
}
}
`, bucketName),
Check: resource.ComposeTestCheckFunc(
isSnapshotPresent(tt, "scaleway_instance_snapshot.qcow-instance-snapshot"),
acctest.CheckResourceAttrUUID("scaleway_instance_snapshot.qcow-instance-snapshot", "id"),
resource.TestCheckResourceAttr("scaleway_instance_snapshot.qcow-instance-snapshot", "name", "test-acc-snapshot-import-default"),
resource.TestCheckResourceAttr("scaleway_instance_snapshot.qcow-instance-snapshot", "type", "l_ssd"),
),
},
{
Config: fmt.Sprintf(`
resource "scaleway_object_bucket" "snapshot-bucket" {
name = "%s"
}

resource "scaleway_object" "qcow-object" {
bucket = scaleway_object_bucket.snapshot-bucket.name
key = "test-acc-instance-snapshot.qcow2"
file = "testfixture/small_image.qcow2"
}

resource "scaleway_instance_snapshot" "qcow-instance-snapshot" {
name = "test-acc-snapshot-import-lssd"
type = "l_ssd"
import {
bucket = scaleway_object.qcow-object.bucket
key = scaleway_object.qcow-object.key
}
}
`, bucketName),
Check: resource.ComposeTestCheckFunc(
isSnapshotPresent(tt, "scaleway_instance_snapshot.qcow-instance-snapshot"),
acctest.CheckResourceAttrUUID("scaleway_instance_snapshot.qcow-instance-snapshot", "id"),
resource.TestCheckResourceAttr("scaleway_instance_snapshot.qcow-instance-snapshot", "name", "test-acc-snapshot-import-lssd"),
resource.TestCheckResourceAttr("scaleway_instance_snapshot.qcow-instance-snapshot", "type", "l_ssd"),
),
},
},
})
}

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