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 059d060 + 36a1f88 commit b3ad3dc
Show file tree
Hide file tree
Showing 10 changed files with 1,250 additions and 2,156 deletions.
5 changes: 5 additions & 0 deletions docs/resources/cockpit.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ page_title: "Scaleway: scaleway_cockpit"
As of September 2024, Cockpit has introduced [regionalization](https://www.scaleway.com/en/docs/observability/cockpit/concepts/#region) to offer more flexibility and resilience.
If you have created customized dashboards with data for your Scaleway resources before April 2024, you will need to update your queries in Grafana, with the new regionalized [data sources](../resources/cockpit_source.md).

-> **Note:**
Cockpit plans scheduled for deprecation on January 1st 2025.
The retention period previously set for your logs and metrics will remain the same after that date.
You will be able to edit the retention period for your metrics, logs, and traces for free during Beta.

Please note that even if you provide the grafana_url, it will only be active if a [Grafana user](../resources/cockpit_grafana_user.md) is created first. Make sure to create a Grafana user in your Cockpit instance to enable full access to Grafana.

The `scaleway_cockpit` resource allows you to create and manage Scaleway Cockpit instances.
Expand Down
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
11 changes: 5 additions & 6 deletions internal/services/cockpit/cockpit.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func ResourceCockpitCreate(ctx context.Context, d *schema.ResourceData, m interf
if targetPlanI, ok := d.GetOk("plan"); ok {
targetPlan := targetPlanI.(string)

plans, err := api.ListPlans(&cockpit.GlobalAPIListPlansRequest{}, scw.WithContext(ctx), scw.WithAllPages())
plans, err := api.ListPlans(&cockpit.GlobalAPIListPlansRequest{}, scw.WithContext(ctx), scw.WithAllPages()) //nolint:staticcheck
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -120,7 +120,7 @@ func ResourceCockpitCreate(ctx context.Context, d *schema.ResourceData, m interf
return diag.Errorf("plan %s not found", targetPlan)
}

_, err = api.SelectPlan(&cockpit.GlobalAPISelectPlanRequest{
_, err = api.SelectPlan(&cockpit.GlobalAPISelectPlanRequest{ //nolint:staticcheck
ProjectID: projectID,
PlanName: cockpit.PlanName(planName),
}, scw.WithContext(ctx))
Expand Down Expand Up @@ -150,8 +150,7 @@ func ResourceCockpitRead(ctx context.Context, d *schema.ResourceData, m interfac
return diag.FromErr(err)
}
}

res, err := api.GetCurrentPlan(&cockpit.GlobalAPIGetCurrentPlanRequest{
res, err := api.GetCurrentPlan(&cockpit.GlobalAPIGetCurrentPlanRequest{ //nolint:staticcheck
ProjectID: projectID,
}, scw.WithContext(ctx))
if err != nil {
Expand Down Expand Up @@ -214,7 +213,7 @@ func ResourceCockpitUpdate(ctx context.Context, d *schema.ResourceData, m interf
targetPlan = targetPlanI.(string)
}

plans, err := api.ListPlans(&cockpit.GlobalAPIListPlansRequest{}, scw.WithContext(ctx), scw.WithAllPages())
plans, err := api.ListPlans(&cockpit.GlobalAPIListPlansRequest{}, scw.WithContext(ctx), scw.WithAllPages()) //nolint:staticcheck
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -231,7 +230,7 @@ func ResourceCockpitUpdate(ctx context.Context, d *schema.ResourceData, m interf
return diag.Errorf("plan %s not found", targetPlan)
}

_, err = api.SelectPlan(&cockpit.GlobalAPISelectPlanRequest{
_, err = api.SelectPlan(&cockpit.GlobalAPISelectPlanRequest{ //nolint:staticcheck
ProjectID: projectID,
PlanName: cockpit.PlanName(planName),
}, scw.WithContext(ctx))
Expand Down
2 changes: 1 addition & 1 deletion internal/services/cockpit/cockpit_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func dataSourceCockpitRead(ctx context.Context, d *schema.ResourceData, m interf
}
}

res, err := api.GetCurrentPlan(&cockpit.GlobalAPIGetCurrentPlanRequest{
res, err := api.GetCurrentPlan(&cockpit.GlobalAPIGetCurrentPlanRequest{ //nolint:staticcheck
ProjectID: projectID,
}, scw.WithContext(ctx))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/cockpit/plan_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func DataSourceCockpitPlanRead(ctx context.Context, d *schema.ResourceData, m in

name := d.Get("name").(string)

res, err := api.ListPlans(&cockpit.GlobalAPIListPlansRequest{}, scw.WithContext(ctx), scw.WithAllPages())
res, err := api.ListPlans(&cockpit.GlobalAPIListPlansRequest{}, scw.WithContext(ctx), scw.WithAllPages()) //nolint:staticcheck
if err != nil {
return diag.FromErr(err)
}
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 b3ad3dc

Please sign in to comment.