Skip to content

Commit 46ebe46

Browse files
MonitobCodelax
andauthored
feat(scaleway_instance_snapshot): volume type unified (#1300)
Co-authored-by: Jules Castéran <[email protected]>
1 parent 8dbe972 commit 46ebe46

5 files changed

+5966
-1746
lines changed

docs/resources/instance_snapshot.md

+37-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Manages Scaleway Instance Snapshots.
77
# scaleway_instance_snapshot
88

99
Creates and manages Scaleway Compute Snapshots.
10-
For more information, see [the documentation](https://developers.scaleway.com/en/products/instance/api/#snapshots-756fae).
10+
For more information,
11+
see [the documentation](https://developers.scaleway.com/en/products/instance/api/#snapshots-756fae).
1112

1213
## Example
1314

@@ -18,16 +19,49 @@ resource "scaleway_instance_snapshot" "main" {
1819
}
1920
```
2021

22+
## Example with Unified type
23+
24+
```hcl
25+
resource "scaleway_instance_volume" "main" {
26+
type = "l_ssd"
27+
size_in_gb = 10
28+
}
29+
30+
resource "scaleway_instance_server" "main" {
31+
image = "ubuntu_jammy"
32+
type = "DEV1-S"
33+
root_volume {
34+
size_in_gb = 10
35+
volume_type = "l_ssd"
36+
}
37+
additional_volume_ids = [
38+
scaleway_instance_volume.main.id
39+
]
40+
}
41+
42+
resource "scaleway_instance_snapshot" "main" {
43+
volume_id = scaleway_instance_volume.main.id
44+
type = "unified"
45+
depends_on = [scaleway_instance_server.main]
46+
}
47+
```
48+
2149
## Arguments Reference
2250

2351
The following arguments are supported:
2452

2553
- `volume_id` - (Required) The ID of the volume to take a snapshot from.
54+
- `type` - (Optional) The snapshot's volume type. The possible values are: `b_ssd` (Block SSD), `l_ssd` (Local SSD) and `unified`.
55+
Updates to this field will recreate a new resource.
2656
- `name` - (Optional) The name of the snapshot. If not provided it will be randomly generated.
27-
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the snapshot should be created.
28-
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the snapshot is associated with.
57+
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which
58+
the snapshot should be created.
59+
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the snapshot is
60+
associated with.
2961
- `tags` - (Optional) A list of tags to apply to the snapshot.
3062

63+
-> **Note:** The type `unified` could be instantiated on both `l_ssd` and `b_ssd` volumes.
64+
3165
## Attributes Reference
3266

3367
In addition to all above arguments, the following attributes are exported:
@@ -36,7 +70,6 @@ In addition to all above arguments, the following attributes are exported:
3670
- `size_in_gb` - (Optional) The size of the snapshot.
3771
- `organization_id` - The organization ID the snapshot is associated with.
3872
- `project_id` - The project ID the snapshot is associated with.
39-
- `type` - The type of the snapshot. The possible values are: `b_ssd` (Block SSD), `l_ssd` (Local SSD).
4073
- `created_at` - The snapshot creation time.
4174

4275
## Import

scaleway/resource_instance_snapshot.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1011
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
1112
"github.com/scaleway/scaleway-sdk-go/scw"
1213
)
@@ -42,8 +43,16 @@ func resourceScalewayInstanceSnapshot() *schema.Resource {
4243
},
4344
"type": {
4445
Type: schema.TypeString,
46+
Optional: true,
4547
Computed: true,
46-
Description: "The volume type of the snapshot",
48+
ForceNew: true,
49+
Description: "The snapshot's volume type",
50+
ValidateFunc: validation.StringInSlice([]string{
51+
instance.SnapshotVolumeTypeUnknownVolumeType.String(),
52+
instance.SnapshotVolumeTypeBSSD.String(),
53+
instance.SnapshotVolumeTypeLSSD.String(),
54+
instance.SnapshotVolumeTypeUnified.String(),
55+
}, false),
4756
},
4857
"size_in_gb": {
4958
Type: schema.TypeInt,
@@ -82,6 +91,11 @@ func resourceScalewayInstanceSnapshotCreate(ctx context.Context, d *schema.Resou
8291
Name: expandOrGenerateString(d.Get("name"), "snap"),
8392
VolumeID: expandZonedID(d.Get("volume_id").(string)).ID,
8493
}
94+
95+
if volumeType, ok := d.GetOk("type"); ok {
96+
volumeType := instance.SnapshotVolumeType(volumeType.(string))
97+
req.VolumeType = volumeType
98+
}
8599
tags := expandStrings(d.Get("tags"))
86100
if len(tags) > 0 {
87101
req.Tags = tags

scaleway/resource_instance_snapshot_test.go

+51-6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,48 @@ func TestAccScalewayInstanceSnapshot_BlockVolume(t *testing.T) {
3535
})
3636
}
3737

38+
func TestAccScalewayInstanceSnapshot_Unified(t *testing.T) {
39+
tt := NewTestTools(t)
40+
defer tt.Cleanup()
41+
resource.Test(t, resource.TestCase{
42+
PreCheck: func() { testAccPreCheck(t) },
43+
ProviderFactories: tt.ProviderFactories,
44+
CheckDestroy: testAccCheckScalewayInstanceVolumeDestroy(tt),
45+
Steps: []resource.TestStep{
46+
{
47+
Config: `
48+
resource "scaleway_instance_volume" "main" {
49+
type = "l_ssd"
50+
size_in_gb = 10
51+
}
52+
53+
resource "scaleway_instance_server" "main" {
54+
image = "ubuntu_jammy"
55+
type = "DEV1-S"
56+
root_volume {
57+
size_in_gb = 10
58+
volume_type = "l_ssd"
59+
}
60+
additional_volume_ids = [
61+
scaleway_instance_volume.main.id
62+
]
63+
}
64+
65+
resource "scaleway_instance_snapshot" "main" {
66+
volume_id = scaleway_instance_volume.main.id
67+
type = "unified"
68+
depends_on = [scaleway_instance_server.main]
69+
}
70+
`,
71+
Check: resource.ComposeTestCheckFunc(
72+
testAccCheckScalewayInstanceSnapShotExists(tt, "scaleway_instance_snapshot.main"),
73+
resource.TestCheckResourceAttr("scaleway_instance_snapshot.main", "type", "unified"),
74+
),
75+
},
76+
},
77+
})
78+
}
79+
3880
func TestAccScalewayInstanceSnapshot_Server(t *testing.T) {
3981
tt := NewTestTools(t)
4082
defer tt.Cleanup()
@@ -75,22 +117,25 @@ func TestAccScalewayInstanceSnapshot_ServerWithBlockVolume(t *testing.T) {
75117
Steps: []resource.TestStep{
76118
{
77119
Config: `
78-
resource "scaleway_instance_volume" "block" {
120+
resource "scaleway_instance_volume" main {
79121
type = "b_ssd"
80122
size_in_gb = 10
81123
}
82124
83-
resource "scaleway_instance_server" "main" {
125+
resource "scaleway_instance_server" main {
84126
image = "ubuntu_focal"
85127
type = "DEV1-S"
86-
128+
root_volume {
129+
size_in_gb = 10
130+
volume_type = "l_ssd"
131+
}
87132
additional_volume_ids = [
88-
scaleway_instance_volume.block.id
133+
scaleway_instance_volume.main.id
89134
]
90135
}
91136
92-
resource "scaleway_instance_snapshot" "main" {
93-
volume_id = scaleway_instance_volume.block.id
137+
resource "scaleway_instance_snapshot" main {
138+
volume_id = scaleway_instance_volume.main.id
94139
}`,
95140
Check: resource.ComposeTestCheckFunc(
96141
testAccCheckScalewayInstanceSnapShotExists(tt, "scaleway_instance_snapshot.main"),

0 commit comments

Comments
 (0)