Skip to content

Commit 5cbe1f4

Browse files
committed
add tests for zone and backup, lint, naming nits
1 parent e3fd055 commit 5cbe1f4

File tree

5 files changed

+315
-36
lines changed

5 files changed

+315
-36
lines changed

internal/services/instance/action_create_snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (c *CreateSnapshot) Schema(_ context.Context, _ action.SchemaRequest, resp
8080
},
8181
"wait": schema.BoolAttribute{
8282
Optional: true,
83-
Description: "Wait for snapshotting operation to be finished",
83+
Description: "Wait for snapshotting operation to be completed",
8484
},
8585
},
8686
}

internal/services/instance/action_create_snapshot_test.go

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestAccAction_InstanceCreateSnapshot_Local(t *testing.T) {
4242
{
4343
Config: fmt.Sprintf(`
4444
resource "scaleway_instance_server" "main" {
45-
name = "test-terraform-action-instance-create-snapshot"
45+
name = "test-tf-action-instance-create-snapshot-local"
4646
type = "DEV1-S"
4747
image = "ubuntu_jammy"
4848
@@ -83,7 +83,7 @@ func TestAccAction_InstanceCreateSnapshot_Local(t *testing.T) {
8383
{
8484
Config: fmt.Sprintf(`
8585
resource "scaleway_instance_server" "main" {
86-
name = "test-terraform-action-instance-create-snapshot"
86+
name = "test-tf-action-instance-create-snapshot-local"
8787
type = "DEV1-S"
8888
image = "ubuntu_jammy"
8989
tags = [ "add", "tags", "to", "trigger", "update" ]
@@ -142,13 +142,12 @@ func TestAccAction_InstanceCreateSnapshot_Scratch(t *testing.T) {
142142

143143
resource.ParallelTest(t, resource.TestCase{
144144
ProtoV6ProviderFactories: tt.ProviderFactories,
145-
CheckDestroy: resource.ComposeTestCheckFunc(
146-
instancechecks.IsVolumeDestroyed(tt),
147-
),
145+
CheckDestroy: instancechecks.IsServerDestroyed(tt),
148146
Steps: []resource.TestStep{
149147
{
150148
Config: fmt.Sprintf(`
151149
resource "scaleway_instance_volume" "scratch" {
150+
name = "test-tf-action-instance-create-snapshot-scratch"
152151
type = "%s"
153152
size_in_gb = 50
154153
@@ -172,6 +171,71 @@ func TestAccAction_InstanceCreateSnapshot_Scratch(t *testing.T) {
172171
})
173172
}
174173

174+
func TestAccAction_InstanceCreateSnapshot_Zone(t *testing.T) {
175+
if acctest.IsRunningOpenTofu() {
176+
t.Skip("Skipping TestAccAction_InstanceCreateSnapshot_Zone because action are not yet supported on OpenTofu")
177+
}
178+
179+
tt := acctest.NewTestTools(t)
180+
defer tt.Cleanup()
181+
182+
localVolumeType := instanceSDK.VolumeVolumeTypeLSSD
183+
184+
resource.ParallelTest(t, resource.TestCase{
185+
ProtoV6ProviderFactories: tt.ProviderFactories,
186+
CheckDestroy: resource.ComposeTestCheckFunc(
187+
instancechecks.IsServerDestroyed(tt),
188+
destroyUntrackedSnapshots(tt, "data.scaleway_instance_volume.main"),
189+
),
190+
Steps: []resource.TestStep{
191+
{
192+
Config: fmt.Sprintf(`
193+
resource "scaleway_instance_server" "main" {
194+
name = "test-tf-action-instance-create-snapshot-zone"
195+
type = "DEV1-S"
196+
image = "ubuntu_jammy"
197+
zone = "fr-par-2"
198+
199+
root_volume {
200+
volume_type = "%s"
201+
size_in_gb = 20
202+
}
203+
204+
lifecycle {
205+
action_trigger {
206+
events = [after_create]
207+
actions = [action.scaleway_instance_create_snapshot.main]
208+
}
209+
}
210+
}
211+
212+
data "scaleway_instance_volume" "main" {
213+
volume_id = scaleway_instance_server.main.root_volume.0.volume_id
214+
zone = "fr-par-2"
215+
}
216+
217+
action "scaleway_instance_create_snapshot" "main" {
218+
config {
219+
volume_id = scaleway_instance_server.main.root_volume.0.volume_id
220+
wait = true
221+
}
222+
}`, localVolumeType),
223+
},
224+
{
225+
RefreshState: true,
226+
Check: resource.ComposeTestCheckFunc(
227+
instancechecks.IsVolumePresent(tt, "data.scaleway_instance_volume.main"),
228+
resource.TestCheckResourceAttr("scaleway_instance_server.main", "zone", "fr-par-2"),
229+
checkSnapshot(tt, "data.scaleway_instance_volume.main", snapshotSpecsCheck{
230+
Size: scw.SizePtr(20 * scw.GB),
231+
Type: &localVolumeType,
232+
}),
233+
),
234+
},
235+
},
236+
})
237+
}
238+
175239
func snapshotMatchesExpectedSpecs(snapshot instanceSDK.Snapshot, expected snapshotSpecsCheck) bool {
176240
if expected.Name != nil && *expected.Name != snapshot.Name {
177241
return false

internal/services/instance/action_export_snapshot_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
objectchecks "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/object/testfuncs"
1919
)
2020

21+
const snapshotKey = "exported-snapshot.qcow2"
22+
2123
func TestAccAction_InstanceExportSnapshot(t *testing.T) {
2224
if acctest.IsRunningOpenTofu() {
2325
t.Skip("Skipping TestAccAction_InstanceExportSnapshot because action are not yet supported on OpenTofu")
@@ -26,14 +28,14 @@ func TestAccAction_InstanceExportSnapshot(t *testing.T) {
2628
tt := acctest.NewTestTools(t)
2729
defer tt.Cleanup()
2830

29-
bucketName := ""
31+
var bucketName string
3032
for {
3133
bucketName = sdkacctest.RandomWithPrefix("test-acc-action-instance-export-snapshot")
3234
if len(bucketName) < 63 {
3335
break
3436
}
3537
}
36-
snapshotKey := "exported-snapshot.qcow2"
38+
3739
size := 10
3840

3941
resource.ParallelTest(t, resource.TestCase{
@@ -148,14 +150,14 @@ func TestAccAction_InstanceExportSnapshot_Wait(t *testing.T) {
148150
tt := acctest.NewTestTools(t)
149151
defer tt.Cleanup()
150152

151-
bucketName := ""
153+
var bucketName string
152154
for {
153155
bucketName = sdkacctest.RandomWithPrefix("test-acc-action-instance-export-snap-wait")
154156
if len(bucketName) < 63 {
155157
break
156158
}
157159
}
158-
snapshotKey := "exported-snapshot.qcow2"
160+
159161
size := 10
160162

161163
resource.ParallelTest(t, resource.TestCase{
@@ -266,14 +268,14 @@ func TestAccAction_InstanceExportSnapshot_Zone(t *testing.T) {
266268
tt := acctest.NewTestTools(t)
267269
defer tt.Cleanup()
268270

269-
bucketName := ""
271+
var bucketName string
270272
for {
271273
bucketName = sdkacctest.RandomWithPrefix("test-acc-action-instance-export-snap-zone")
272274
if len(bucketName) < 63 {
273275
break
274276
}
275277
}
276-
snapshotKey := "exported-snapshot.qcow2"
278+
277279
size := 10
278280

279281
resource.ParallelTest(t, resource.TestCase{

0 commit comments

Comments
 (0)