Skip to content

Commit

Permalink
fix(instance_snapshot): ignore region in bucket field (#2472)
Browse files Browse the repository at this point in the history
* fix(instance_snapshot): ignore region in bucket field

* add test

* add cassette

* fix tfproviderlint

* add testfixture
  • Loading branch information
Codelax committed Mar 25, 2024
1 parent ad73deb commit 9af8086
Show file tree
Hide file tree
Showing 4 changed files with 4,840 additions and 5 deletions.
15 changes: 10 additions & 5 deletions scaleway/resource_instance_snapshot.go
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/transport"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
Expand Down Expand Up @@ -80,10 +81,14 @@ func ResourceScalewayInstanceSnapshot() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"bucket": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Bucket containing qcow",
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Bucket containing qcow",
DiffSuppressFunc: diffSuppressFuncLocality,
StateFunc: func(i interface{}) string {
return regional.ExpandID(i.(string)).ID
},
},
"key": {
Type: schema.TypeString,
Expand Down Expand Up @@ -134,7 +139,7 @@ func resourceScalewayInstanceSnapshotCreate(ctx context.Context, d *schema.Resou
}

if _, isImported := d.GetOk("import"); isImported {
req.Bucket = types.ExpandStringPtr(d.Get("import.0.bucket"))
req.Bucket = types.ExpandStringPtr(regional.ExpandID(d.Get("import.0.bucket")).ID)
req.Key = types.ExpandStringPtr(d.Get("import.0.key"))
}

Expand Down
36 changes: 36 additions & 0 deletions scaleway/resource_instance_snapshot_test.go
Expand Up @@ -228,6 +228,42 @@ func TestAccScalewayInstanceSnapshot_RenameSnapshot(t *testing.T) {
})
}

func TestAccScalewayInstanceSnapshot_FromObject(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: testAccCheckScalewayInstanceVolumeDestroy(tt),
Steps: []resource.TestStep{
{
Config: `
resource "scaleway_object_bucket" "bucket" {
name = "test-instance-snapshot-import-from-object"
}
resource "scaleway_object" "image" {
bucket = scaleway_object_bucket.bucket.name
key = "image.qcow"
file = "testfixture/empty.qcow2"
}
resource "scaleway_instance_snapshot" "snapshot" {
name = "test-instance-snapshot-import-from-object"
type = "b_ssd"
import {
bucket = scaleway_object.image.bucket
key = scaleway_object.image.key
}
}`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayInstanceSnapShotExists(tt, "scaleway_instance_snapshot.snapshot"),
),
},
},
})
}

func testAccCheckScalewayInstanceSnapShotExists(tt *acctest.TestTools, n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down

0 comments on commit 9af8086

Please sign in to comment.