Skip to content

Commit

Permalink
feat(scaleway_instance_snapshot): volume type unified (#1300)
Browse files Browse the repository at this point in the history
Co-authored-by: Jules Castéran <jcasteran@scaleway.com>
  • Loading branch information
Monitob and Codelax committed Jul 18, 2022
1 parent 8dbe972 commit 46ebe46
Show file tree
Hide file tree
Showing 5 changed files with 5,966 additions and 1,746 deletions.
41 changes: 37 additions & 4 deletions docs/resources/instance_snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Manages Scaleway Instance Snapshots.
# scaleway_instance_snapshot

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

## Example

Expand All @@ -18,16 +19,49 @@ resource "scaleway_instance_snapshot" "main" {
}
```

## Example with Unified type

```hcl
resource "scaleway_instance_volume" "main" {
type = "l_ssd"
size_in_gb = 10
}
resource "scaleway_instance_server" "main" {
image = "ubuntu_jammy"
type = "DEV1-S"
root_volume {
size_in_gb = 10
volume_type = "l_ssd"
}
additional_volume_ids = [
scaleway_instance_volume.main.id
]
}
resource "scaleway_instance_snapshot" "main" {
volume_id = scaleway_instance_volume.main.id
type = "unified"
depends_on = [scaleway_instance_server.main]
}
```

## Arguments Reference

The following arguments are supported:

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

-> **Note:** The type `unified` could be instantiated on both `l_ssd` and `b_ssd` volumes.

## Attributes Reference

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

## Import
Expand Down
16 changes: 15 additions & 1 deletion scaleway/resource_instance_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
)
Expand Down Expand Up @@ -42,8 +43,16 @@ func resourceScalewayInstanceSnapshot() *schema.Resource {
},
"type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The volume type of the snapshot",
ForceNew: true,
Description: "The snapshot's volume type",
ValidateFunc: validation.StringInSlice([]string{
instance.SnapshotVolumeTypeUnknownVolumeType.String(),
instance.SnapshotVolumeTypeBSSD.String(),
instance.SnapshotVolumeTypeLSSD.String(),
instance.SnapshotVolumeTypeUnified.String(),
}, false),
},
"size_in_gb": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -82,6 +91,11 @@ func resourceScalewayInstanceSnapshotCreate(ctx context.Context, d *schema.Resou
Name: expandOrGenerateString(d.Get("name"), "snap"),
VolumeID: expandZonedID(d.Get("volume_id").(string)).ID,
}

if volumeType, ok := d.GetOk("type"); ok {
volumeType := instance.SnapshotVolumeType(volumeType.(string))
req.VolumeType = volumeType
}
tags := expandStrings(d.Get("tags"))
if len(tags) > 0 {
req.Tags = tags
Expand Down
57 changes: 51 additions & 6 deletions scaleway/resource_instance_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,48 @@ func TestAccScalewayInstanceSnapshot_BlockVolume(t *testing.T) {
})
}

func TestAccScalewayInstanceSnapshot_Unified(t *testing.T) {
tt := NewTestTools(t)
defer tt.Cleanup()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: testAccCheckScalewayInstanceVolumeDestroy(tt),
Steps: []resource.TestStep{
{
Config: `
resource "scaleway_instance_volume" "main" {
type = "l_ssd"
size_in_gb = 10
}
resource "scaleway_instance_server" "main" {
image = "ubuntu_jammy"
type = "DEV1-S"
root_volume {
size_in_gb = 10
volume_type = "l_ssd"
}
additional_volume_ids = [
scaleway_instance_volume.main.id
]
}
resource "scaleway_instance_snapshot" "main" {
volume_id = scaleway_instance_volume.main.id
type = "unified"
depends_on = [scaleway_instance_server.main]
}
`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayInstanceSnapShotExists(tt, "scaleway_instance_snapshot.main"),
resource.TestCheckResourceAttr("scaleway_instance_snapshot.main", "type", "unified"),
),
},
},
})
}

func TestAccScalewayInstanceSnapshot_Server(t *testing.T) {
tt := NewTestTools(t)
defer tt.Cleanup()
Expand Down Expand Up @@ -75,22 +117,25 @@ func TestAccScalewayInstanceSnapshot_ServerWithBlockVolume(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
resource "scaleway_instance_volume" "block" {
resource "scaleway_instance_volume" main {
type = "b_ssd"
size_in_gb = 10
}
resource "scaleway_instance_server" "main" {
resource "scaleway_instance_server" main {
image = "ubuntu_focal"
type = "DEV1-S"
root_volume {
size_in_gb = 10
volume_type = "l_ssd"
}
additional_volume_ids = [
scaleway_instance_volume.block.id
scaleway_instance_volume.main.id
]
}
resource "scaleway_instance_snapshot" "main" {
volume_id = scaleway_instance_volume.block.id
resource "scaleway_instance_snapshot" main {
volume_id = scaleway_instance_volume.main.id
}`,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayInstanceSnapShotExists(tt, "scaleway_instance_snapshot.main"),
Expand Down

0 comments on commit 46ebe46

Please sign in to comment.