Skip to content

Commit

Permalink
Merge branch 'master' into feat/Migrate_sqs_from_v1_to_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jremy42 authored Dec 10, 2024
2 parents a5bd5d9 + 3d9d4ff commit 64d4939
Show file tree
Hide file tree
Showing 6 changed files with 1,238 additions and 2,148 deletions.
2 changes: 1 addition & 1 deletion docs/resources/instance_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ To retrieve more information by label please use: ```scw marketplace image get l
- `size_in_gb` - (Required) Size of the root volume in gigabytes.
To find the right size use [this endpoint](https://www.scaleway.com/en/developers/api/instance/#path-instances-list-all-instances) and
check the `volumes_constraint.{min|max}_size` (in bytes) for your `commercial_type`.
Updates to this field will recreate a new resource.
Depending on `volume_type`, updates to this field may recreate a new resource.
- `volume_type` - (Optional) Volume type of root volume, can be `b_ssd`, `l_ssd` or `sbs_volume`, default value depends on server type
- `delete_on_termination` - (Defaults to `true`) Forces deletion of the root volume on instance termination.
- `sbs_iops` - (Optional) Choose IOPS of your sbs volume, has to be used with `sbs_volume` for root volume type.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/vpc_gateway_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ The following arguments are supported:
- `private_network_id` - (Required) The ID of the Private Network.
- `dhcp_id` - (Required) The ID of the Public Gateway DHCP configuration. Only one of `dhcp_id`, `static_address` and `ipam_config` should be specified.
- `enable_masquerade` - (Defaults to true) Whether masquerade (dynamic NAT) should be enabled on this GatewayNetwork
- `enable_dhcp` - (Defaults to true) WWhether a DHCP configuration should be enabled on this GatewayNetwork. Requires a DHCP ID.
- `enable_dhcp` - (Defaults to true) Whether a DHCP configuration should be enabled on this GatewayNetwork. Requires a DHCP ID.
- `cleanup_dhcp` - (Defaults to false) Whether to remove DHCP configuration on this GatewayNetwork upon destroy. Requires DHCP ID.
- `static_address` - Enable DHCP configration on this GatewayNetwork. Only one of `dhcp_id`, `static_address` and `ipam_config` should be specified.
- `ipam_config` - Auto-configure the GatewayNetwork using Scaleway's IPAM (IP address management service). Only one of `dhcp_id`, `static_address` and `ipam_config` should be specified.
Expand Down
29 changes: 28 additions & 1 deletion internal/services/instance/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func ResourceServer() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
Description: "Size of the root volume in gigabytes",
},
"volume_type": {
Expand Down Expand Up @@ -374,6 +373,7 @@ func ResourceServer() *schema.Resource {
),
customDiffInstanceServerType,
customDiffInstanceServerImage,
customDiffInstanceRootVolumeSize,
),
}
}
Expand Down Expand Up @@ -1169,6 +1169,33 @@ func instanceServerCanMigrate(api *instanceSDK.API, server *instanceSDK.Server,
return nil
}

func customDiffInstanceRootVolumeSize(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
if !diff.HasChange("root_volume.0.size_in_gb") || diff.Id() == "" {
return nil
}

instanceAPI, zone, id, err := NewAPIWithZoneAndID(meta, diff.Id())
if err != nil {
return err
}

resp, err := instanceAPI.GetServer(&instanceSDK.GetServerRequest{
Zone: zone,
ServerID: id,
})
if err != nil {
return fmt.Errorf("failed to check server root volume type: %w", err)
}

if rootVolume, hasRootVolume := resp.Server.Volumes["0"]; hasRootVolume {
if rootVolume.VolumeType == instanceSDK.VolumeServerVolumeTypeLSSD {
return diff.ForceNew("root_volume.0.size_in_gb")
}
}

return nil
}

func customDiffInstanceServerType(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
if !diff.HasChange("type") || diff.Id() == "" {
return nil
Expand Down
10 changes: 10 additions & 0 deletions internal/services/instance/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ func TestAccServer_Minimal2(t *testing.T) {
func TestAccServer_RootVolume1(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()

serverID := ""

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
Expand All @@ -166,6 +169,7 @@ func TestAccServer_RootVolume1(t *testing.T) {
isServerPresent(tt, "scaleway_instance_server.base"),
serverHasNewVolume(tt, "scaleway_instance_server.base"),
resource.TestCheckResourceAttr("scaleway_instance_server.base", "root_volume.0.size_in_gb", "10"),
acctest.CheckResourceIDPersisted("scaleway_instance_server.base", &serverID),
),
},
{
Expand All @@ -183,6 +187,7 @@ func TestAccServer_RootVolume1(t *testing.T) {
isServerPresent(tt, "scaleway_instance_server.base"),
serverHasNewVolume(tt, "scaleway_instance_server.base"),
resource.TestCheckResourceAttr("scaleway_instance_server.base", "root_volume.0.size_in_gb", "20"),
acctest.CheckResourceIDChanged("scaleway_instance_server.base", &serverID), // Server should have been re-created as l_ssd cannot be resized.
),
},
},
Expand Down Expand Up @@ -1702,6 +1707,9 @@ func TestAccServer_BlockExternal(t *testing.T) {
func TestAccServer_BlockExternalRootVolume(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()

serverID := ""

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
Expand All @@ -1725,6 +1733,7 @@ func TestAccServer_BlockExternalRootVolume(t *testing.T) {
resource.TestCheckResourceAttr("scaleway_instance_server.main", "root_volume.0.volume_type", string(instanceSDK.VolumeVolumeTypeSbsVolume)),
resource.TestCheckResourceAttr("scaleway_instance_server.main", "root_volume.0.sbs_iops", "15000"),
resource.TestCheckResourceAttr("scaleway_instance_server.main", "root_volume.0.size_in_gb", "50"),
acctest.CheckResourceIDPersisted("scaleway_instance_server.main", &serverID),
),
},
{
Expand All @@ -1745,6 +1754,7 @@ func TestAccServer_BlockExternalRootVolume(t *testing.T) {
resource.TestCheckResourceAttr("scaleway_instance_server.main", "root_volume.0.volume_type", string(instanceSDK.VolumeVolumeTypeSbsVolume)),
resource.TestCheckResourceAttr("scaleway_instance_server.main", "root_volume.0.sbs_iops", "15000"),
resource.TestCheckResourceAttr("scaleway_instance_server.main", "root_volume.0.size_in_gb", "60"),
acctest.CheckResourceIDPersisted("scaleway_instance_server.main", &serverID),
),
},
},
Expand Down
Loading

0 comments on commit 64d4939

Please sign in to comment.