Skip to content

Commit 9af8086

Browse files
authored
fix(instance_snapshot): ignore region in bucket field (#2472)
* fix(instance_snapshot): ignore region in bucket field * add test * add cassette * fix tfproviderlint * add testfixture
1 parent ad73deb commit 9af8086

File tree

4 files changed

+4840
-5
lines changed

4 files changed

+4840
-5
lines changed

scaleway/resource_instance_snapshot.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
1212
"github.com/scaleway/scaleway-sdk-go/scw"
1313
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
14+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
1415
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
1516
"github.com/scaleway/terraform-provider-scaleway/v2/internal/transport"
1617
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
@@ -80,10 +81,14 @@ func ResourceScalewayInstanceSnapshot() *schema.Resource {
8081
Elem: &schema.Resource{
8182
Schema: map[string]*schema.Schema{
8283
"bucket": {
83-
Type: schema.TypeString,
84-
Required: true,
85-
ForceNew: true,
86-
Description: "Bucket containing qcow",
84+
Type: schema.TypeString,
85+
Required: true,
86+
ForceNew: true,
87+
Description: "Bucket containing qcow",
88+
DiffSuppressFunc: diffSuppressFuncLocality,
89+
StateFunc: func(i interface{}) string {
90+
return regional.ExpandID(i.(string)).ID
91+
},
8792
},
8893
"key": {
8994
Type: schema.TypeString,
@@ -134,7 +139,7 @@ func resourceScalewayInstanceSnapshotCreate(ctx context.Context, d *schema.Resou
134139
}
135140

136141
if _, isImported := d.GetOk("import"); isImported {
137-
req.Bucket = types.ExpandStringPtr(d.Get("import.0.bucket"))
142+
req.Bucket = types.ExpandStringPtr(regional.ExpandID(d.Get("import.0.bucket")).ID)
138143
req.Key = types.ExpandStringPtr(d.Get("import.0.key"))
139144
}
140145

scaleway/resource_instance_snapshot_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,42 @@ func TestAccScalewayInstanceSnapshot_RenameSnapshot(t *testing.T) {
228228
})
229229
}
230230

231+
func TestAccScalewayInstanceSnapshot_FromObject(t *testing.T) {
232+
tt := acctest.NewTestTools(t)
233+
defer tt.Cleanup()
234+
resource.ParallelTest(t, resource.TestCase{
235+
PreCheck: func() { acctest.PreCheck(t) },
236+
ProviderFactories: tt.ProviderFactories,
237+
CheckDestroy: testAccCheckScalewayInstanceVolumeDestroy(tt),
238+
Steps: []resource.TestStep{
239+
{
240+
Config: `
241+
resource "scaleway_object_bucket" "bucket" {
242+
name = "test-instance-snapshot-import-from-object"
243+
}
244+
245+
resource "scaleway_object" "image" {
246+
bucket = scaleway_object_bucket.bucket.name
247+
key = "image.qcow"
248+
file = "testfixture/empty.qcow2"
249+
}
250+
251+
resource "scaleway_instance_snapshot" "snapshot" {
252+
name = "test-instance-snapshot-import-from-object"
253+
type = "b_ssd"
254+
import {
255+
bucket = scaleway_object.image.bucket
256+
key = scaleway_object.image.key
257+
}
258+
}`,
259+
Check: resource.ComposeTestCheckFunc(
260+
testAccCheckScalewayInstanceSnapShotExists(tt, "scaleway_instance_snapshot.snapshot"),
261+
),
262+
},
263+
},
264+
})
265+
}
266+
231267
func testAccCheckScalewayInstanceSnapShotExists(tt *acctest.TestTools, n string) resource.TestCheckFunc {
232268
return func(s *terraform.State) error {
233269
rs, ok := s.RootModule().Resources[n]

0 commit comments

Comments
 (0)