Skip to content

Commit 78ecf16

Browse files
authored
fix(instance): warn on deprecated volume_types values (#3147)
* remove skipped tests
1 parent 8505cd4 commit 78ecf16

File tree

3 files changed

+570
-696
lines changed

3 files changed

+570
-696
lines changed

internal/services/instance/snapshot.go

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ func ResourceInstanceSnapshotCreate(ctx context.Context, d *schema.ResourceData,
130130
req.VolumeType = volumeType
131131
}
132132

133+
diags := handleDeprecatedSnapshotVolumeType(d)
134+
if diags.HasError() {
135+
return diags
136+
}
137+
133138
req.Tags = types.ExpandStringsPtr(d.Get("tags"))
134139

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

189+
diags := handleDeprecatedSnapshotVolumeType(d)
190+
if diags.HasError() {
191+
return diags
192+
}
193+
184194
_ = d.Set("name", snapshot.Snapshot.Name)
185195
_ = d.Set("created_at", snapshot.Snapshot.CreationDate.Format(time.RFC3339))
186196
_ = d.Set("type", snapshot.Snapshot.VolumeType.String())
187197
_ = d.Set("tags", snapshot.Snapshot.Tags)
188198

189-
if d.Get("type").(string) == instanceSDK.VolumeVolumeTypeBSSD.String() {
190-
return diag.Diagnostics{
191-
{
192-
Severity: diag.Warning,
193-
Summary: "Snapshot type `b_ssd` is deprecated",
194-
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.",
195-
AttributePath: cty.GetAttrPath("type"),
196-
},
197-
}
198-
}
199-
200199
return nil
201200
}
202201

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

257256
return nil
258257
}
258+
259+
func handleDeprecatedSnapshotVolumeType(d *schema.ResourceData) diag.Diagnostics {
260+
if d.Get("type").(string) == instanceSDK.SnapshotVolumeTypeBSSD.String() {
261+
return diag.Diagnostics{
262+
{
263+
Severity: diag.Warning,
264+
Summary: "Snapshot type `b_ssd` is deprecated",
265+
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.",
266+
AttributePath: cty.GetAttrPath("type"),
267+
},
268+
}
269+
}
270+
271+
if d.Get("type").(string) == instanceSDK.SnapshotVolumeTypeUnified.String() {
272+
return diag.Diagnostics{
273+
{
274+
Severity: diag.Warning,
275+
Summary: "Snapshot type `unified` is deprecated",
276+
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.",
277+
AttributePath: cty.GetAttrPath("type"),
278+
},
279+
}
280+
}
281+
282+
return diag.Diagnostics{}
283+
}

internal/services/instance/snapshot_test.go

Lines changed: 0 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -13,76 +13,6 @@ import (
1313
instancechecks "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/testfuncs"
1414
)
1515

16-
func TestAccSnapshot_BlockVolume(t *testing.T) {
17-
t.Skip("Resource \"scaleway_instance_snapshot\" is depracated for block volumes")
18-
19-
tt := acctest.NewTestTools(t)
20-
defer tt.Cleanup()
21-
resource.ParallelTest(t, resource.TestCase{
22-
PreCheck: func() { acctest.PreCheck(t) },
23-
ProviderFactories: tt.ProviderFactories,
24-
CheckDestroy: instancechecks.IsVolumeDestroyed(tt),
25-
Steps: []resource.TestStep{
26-
{
27-
Config: `
28-
resource "scaleway_instance_volume" "main" {
29-
type = "b_ssd"
30-
size_in_gb = 20
31-
}
32-
33-
resource "scaleway_instance_snapshot" "main" {
34-
volume_id = scaleway_instance_volume.main.id
35-
}`,
36-
Check: resource.ComposeTestCheckFunc(
37-
isSnapshotPresent(tt, "scaleway_instance_snapshot.main"),
38-
),
39-
},
40-
},
41-
})
42-
}
43-
44-
func TestAccSnapshot_Unified(t *testing.T) {
45-
tt := acctest.NewTestTools(t)
46-
defer tt.Cleanup()
47-
resource.Test(t, resource.TestCase{
48-
PreCheck: func() { acctest.PreCheck(t) },
49-
ProviderFactories: tt.ProviderFactories,
50-
CheckDestroy: instancechecks.IsVolumeDestroyed(tt),
51-
Steps: []resource.TestStep{
52-
{
53-
Config: `
54-
resource "scaleway_instance_volume" "main" {
55-
type = "l_ssd"
56-
size_in_gb = 10
57-
}
58-
59-
resource "scaleway_instance_server" "main" {
60-
image = "ubuntu_jammy"
61-
type = "DEV1-S"
62-
root_volume {
63-
size_in_gb = 10
64-
volume_type = "l_ssd"
65-
}
66-
additional_volume_ids = [
67-
scaleway_instance_volume.main.id
68-
]
69-
}
70-
71-
resource "scaleway_instance_snapshot" "main" {
72-
volume_id = scaleway_instance_volume.main.id
73-
type = "unified"
74-
depends_on = [scaleway_instance_server.main]
75-
}
76-
`,
77-
Check: resource.ComposeTestCheckFunc(
78-
isSnapshotPresent(tt, "scaleway_instance_snapshot.main"),
79-
resource.TestCheckResourceAttr("scaleway_instance_snapshot.main", "type", "unified"),
80-
),
81-
},
82-
},
83-
})
84-
}
85-
8616
func TestAccSnapshot_Server(t *testing.T) {
8717
tt := acctest.NewTestTools(t)
8818
defer tt.Cleanup()
@@ -112,136 +42,6 @@ func TestAccSnapshot_Server(t *testing.T) {
11242
})
11343
}
11444

115-
func TestAccSnapshot_ServerWithBlockVolume(t *testing.T) {
116-
t.Skip("Resource \"scaleway_instance_snapshot\" is depracated for block volumes")
117-
118-
tt := acctest.NewTestTools(t)
119-
defer tt.Cleanup()
120-
resource.ParallelTest(t, resource.TestCase{
121-
PreCheck: func() { acctest.PreCheck(t) },
122-
ProviderFactories: tt.ProviderFactories,
123-
CheckDestroy: resource.ComposeTestCheckFunc(
124-
instancechecks.IsVolumeDestroyed(tt),
125-
instancechecks.IsServerDestroyed(tt),
126-
isSnapshotDestroyed(tt),
127-
),
128-
Steps: []resource.TestStep{
129-
{
130-
Config: `
131-
resource "scaleway_instance_volume" main {
132-
type = "b_ssd"
133-
size_in_gb = 10
134-
}
135-
136-
resource "scaleway_instance_server" main {
137-
image = "ubuntu_focal"
138-
type = "DEV1-S"
139-
root_volume {
140-
size_in_gb = 10
141-
volume_type = "l_ssd"
142-
}
143-
additional_volume_ids = [
144-
scaleway_instance_volume.main.id
145-
]
146-
}
147-
148-
resource "scaleway_instance_snapshot" main {
149-
volume_id = scaleway_instance_volume.main.id
150-
}`,
151-
Check: resource.ComposeTestCheckFunc(
152-
isSnapshotPresent(tt, "scaleway_instance_snapshot.main"),
153-
),
154-
},
155-
},
156-
})
157-
}
158-
159-
func TestAccSnapshot_RenameSnapshot(t *testing.T) {
160-
t.Skip("Resource \"scaleway_instance_snapshot\" is depracated for block volumes")
161-
162-
tt := acctest.NewTestTools(t)
163-
defer tt.Cleanup()
164-
resource.ParallelTest(t, resource.TestCase{
165-
PreCheck: func() { acctest.PreCheck(t) },
166-
ProviderFactories: tt.ProviderFactories,
167-
CheckDestroy: instancechecks.IsVolumeDestroyed(tt),
168-
Steps: []resource.TestStep{
169-
{
170-
Config: `
171-
resource "scaleway_instance_volume" "main" {
172-
type = "b_ssd"
173-
size_in_gb = 20
174-
}
175-
176-
resource "scaleway_instance_snapshot" "main" {
177-
volume_id = scaleway_instance_volume.main.id
178-
name = "first_name"
179-
tags = ["test-terraform"]
180-
}`,
181-
Check: resource.ComposeTestCheckFunc(
182-
isSnapshotPresent(tt, "scaleway_instance_snapshot.main"),
183-
resource.TestCheckResourceAttr("scaleway_instance_snapshot.main", "tags.0", "test-terraform"),
184-
),
185-
},
186-
{
187-
Config: `
188-
resource "scaleway_instance_volume" "main" {
189-
type = "b_ssd"
190-
size_in_gb = 20
191-
}
192-
193-
resource "scaleway_instance_snapshot" "main" {
194-
volume_id = scaleway_instance_volume.main.id
195-
name = "second_name"
196-
}`,
197-
Check: resource.ComposeTestCheckFunc(
198-
isSnapshotPresent(tt, "scaleway_instance_snapshot.main"),
199-
resource.TestCheckResourceAttr("scaleway_instance_snapshot.main", "tags.#", "0"),
200-
),
201-
},
202-
},
203-
})
204-
}
205-
206-
func TestAccSnapshot_FromObject(t *testing.T) {
207-
t.Skip("Resource \"scaleway_instance_snapshot\" is depracated")
208-
// TestAccSnapshot_FromS3 tests the same logic on the scaleway_block_snapshot resource
209-
210-
tt := acctest.NewTestTools(t)
211-
defer tt.Cleanup()
212-
resource.ParallelTest(t, resource.TestCase{
213-
PreCheck: func() { acctest.PreCheck(t) },
214-
ProviderFactories: tt.ProviderFactories,
215-
CheckDestroy: instancechecks.IsVolumeDestroyed(tt),
216-
Steps: []resource.TestStep{
217-
{
218-
Config: `
219-
resource "scaleway_object_bucket" "bucket" {
220-
name = "test-instance-snapshot-import-from-object"
221-
}
222-
223-
resource "scaleway_object" "image" {
224-
bucket = scaleway_object_bucket.bucket.name
225-
key = "image.qcow"
226-
file = "testfixture/empty.qcow2"
227-
}
228-
229-
resource "scaleway_block_snapshot" "snapshot" {
230-
name = "test-instance-snapshot-import-from-object"
231-
type = "b_ssd"
232-
import {
233-
bucket = scaleway_object.image.bucket
234-
key = scaleway_object.image.key
235-
}
236-
}`,
237-
Check: resource.ComposeTestCheckFunc(
238-
isSnapshotPresent(tt, "scaleway_instance_snapshot.snapshot"),
239-
),
240-
},
241-
},
242-
})
243-
}
244-
24545
func isSnapshotPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc {
24646
return func(s *terraform.State) error {
24747
rs, ok := s.RootModule().Resources[n]

0 commit comments

Comments
 (0)