Skip to content

Commit 35070c6

Browse files
authored
Merge branch 'master' into instance_image_additional_volumes_update
2 parents 46d0ea9 + 1ea7ad4 commit 35070c6

File tree

5 files changed

+6933
-5
lines changed

5 files changed

+6933
-5
lines changed

docs/resources/instance_snapshot.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ resource "scaleway_instance_server" "main" {
4040
4141
resource "scaleway_instance_snapshot" "main" {
4242
volume_id = scaleway_instance_volume.main.id
43-
type = "unified"
4443
depends_on = [scaleway_instance_server.main]
4544
}
4645
```
@@ -59,7 +58,6 @@ resource "scaleway_object" "qcow" {
5958
}
6059
6160
resource "scaleway_instance_snapshot" "snapshot" {
62-
type = "unified"
6361
import {
6462
bucket = scaleway_object.qcow.bucket
6563
key = scaleway_object.qcow.key
@@ -72,11 +70,12 @@ resource "scaleway_instance_snapshot" "snapshot" {
7270
The following arguments are supported:
7371

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

7876
~> **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.
7977
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.
78+
~> **Important:** Snapshots of volumes with type `unified` (can be used with both Block and Local SSD) are deprecated since the migration to SBS.
8079

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

91-
-> **Note:** The type `unified` could be instantiated on both `l_ssd` and `b_ssd` volumes.
92-
9390
## Attributes Reference
9491

9592
In addition to all arguments above, the following attributes are exported:

internal/services/instance/snapshot.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ func ResourceInstanceSnapshotCreate(ctx context.Context, d *schema.ResourceData,
142142
}
143143

144144
if _, isImported := d.GetOk("import"); isImported {
145+
if req.VolumeType == "" {
146+
req.VolumeType = instanceSDK.SnapshotVolumeTypeLSSD
147+
}
148+
145149
req.Bucket = types.ExpandStringPtr(regional.ExpandID(d.Get("import.0.bucket")).ID)
146150
req.Key = types.ExpandStringPtr(d.Get("import.0.key"))
147151
}

internal/services/instance/snapshot_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import (
44
"fmt"
55
"testing"
66

7+
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
910
instanceSDK "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
1011
"github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
1112
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
1213
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance"
1314
instancechecks "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/testfuncs"
15+
objectchecks "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/object/testfuncs"
1416
)
1517

1618
func TestAccSnapshot_Server(t *testing.T) {
@@ -42,6 +44,79 @@ func TestAccSnapshot_Server(t *testing.T) {
4244
})
4345
}
4446

47+
func TestAccSnapshot_FromS3(t *testing.T) {
48+
tt := acctest.NewTestTools(t)
49+
defer tt.Cleanup()
50+
51+
bucketName := sdkacctest.RandomWithPrefix("test-acc-scaleway-instance-snapshot")
52+
resource.ParallelTest(t, resource.TestCase{
53+
PreCheck: func() { acctest.PreCheck(t) },
54+
ProviderFactories: tt.ProviderFactories,
55+
CheckDestroy: resource.ComposeTestCheckFunc(
56+
isSnapshotDestroyed(tt),
57+
objectchecks.IsObjectDestroyed(tt),
58+
objectchecks.IsBucketDestroyed(tt),
59+
),
60+
Steps: []resource.TestStep{
61+
{
62+
Config: fmt.Sprintf(`
63+
resource "scaleway_object_bucket" "snapshot-bucket" {
64+
name = "%s"
65+
}
66+
67+
resource "scaleway_object" "qcow-object" {
68+
bucket = scaleway_object_bucket.snapshot-bucket.name
69+
key = "test-acc-instance-snapshot.qcow2"
70+
file = "testfixture/small_image.qcow2"
71+
}
72+
73+
resource "scaleway_instance_snapshot" "qcow-instance-snapshot" {
74+
name = "test-acc-snapshot-import-default"
75+
import {
76+
bucket = scaleway_object.qcow-object.bucket
77+
key = scaleway_object.qcow-object.key
78+
}
79+
}
80+
`, bucketName),
81+
Check: resource.ComposeTestCheckFunc(
82+
isSnapshotPresent(tt, "scaleway_instance_snapshot.qcow-instance-snapshot"),
83+
acctest.CheckResourceAttrUUID("scaleway_instance_snapshot.qcow-instance-snapshot", "id"),
84+
resource.TestCheckResourceAttr("scaleway_instance_snapshot.qcow-instance-snapshot", "name", "test-acc-snapshot-import-default"),
85+
resource.TestCheckResourceAttr("scaleway_instance_snapshot.qcow-instance-snapshot", "type", "l_ssd"),
86+
),
87+
},
88+
{
89+
Config: fmt.Sprintf(`
90+
resource "scaleway_object_bucket" "snapshot-bucket" {
91+
name = "%s"
92+
}
93+
94+
resource "scaleway_object" "qcow-object" {
95+
bucket = scaleway_object_bucket.snapshot-bucket.name
96+
key = "test-acc-instance-snapshot.qcow2"
97+
file = "testfixture/small_image.qcow2"
98+
}
99+
100+
resource "scaleway_instance_snapshot" "qcow-instance-snapshot" {
101+
name = "test-acc-snapshot-import-lssd"
102+
type = "l_ssd"
103+
import {
104+
bucket = scaleway_object.qcow-object.bucket
105+
key = scaleway_object.qcow-object.key
106+
}
107+
}
108+
`, bucketName),
109+
Check: resource.ComposeTestCheckFunc(
110+
isSnapshotPresent(tt, "scaleway_instance_snapshot.qcow-instance-snapshot"),
111+
acctest.CheckResourceAttrUUID("scaleway_instance_snapshot.qcow-instance-snapshot", "id"),
112+
resource.TestCheckResourceAttr("scaleway_instance_snapshot.qcow-instance-snapshot", "name", "test-acc-snapshot-import-lssd"),
113+
resource.TestCheckResourceAttr("scaleway_instance_snapshot.qcow-instance-snapshot", "type", "l_ssd"),
114+
),
115+
},
116+
},
117+
})
118+
}
119+
45120
func isSnapshotPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc {
46121
return func(s *terraform.State) error {
47122
rs, ok := s.RootModule().Resources[n]

0 commit comments

Comments
 (0)