Skip to content

Commit 7c67236

Browse files
committed
Fix
1 parent 4341357 commit 7c67236

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

internal/services/instance/snapshot_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,79 @@ func TestAccSnapshot_Server(t *testing.T) {
4242
})
4343
}
4444

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

0 commit comments

Comments
 (0)