Skip to content

Commit 6878978

Browse files
authored
Merge branch 'master' into feat/inference-deployment-private-ip
2 parents a970814 + eab54f0 commit 6878978

34 files changed

+3958
-38733
lines changed

docs/resources/apple_silicon_server.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ In addition to all arguments above, the following attributes are exported:
4949
- `state` - The state of the server.
5050
- `ip` - IPv4 address of the server (IPv4 address).
5151
- `vnc_url` - URL of the VNC.
52+
- `private_ips` - The list of private IPv4 and IPv6 addresses associated with the server.
53+
- `id` - The ID of the IP address resource.
54+
- `address` - The private IP address.
5255
- `created_at` - The date and time of the creation of the Apple Silicon server.
5356
- `updated_at` - The date and time of the last update of the Apple Silicon server.
5457
- `deleted_at` - The minimal date and time on which you can delete this server due to Apple licence.

docs/resources/instance_snapshot.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ resource "scaleway_instance_snapshot" "snapshot" {
7272
The following arguments are supported:
7373

7474
- `volume_id` - (Optional) The ID of the volume to take a snapshot from.
75-
- `type` - (Optional) The snapshot's volume type. The possible values are: `b_ssd` (Block SSD), `l_ssd` (Local SSD) and `unified`.
75+
- `type` - (Optional) The snapshot's volume type. The possible values are: `l_ssd` (Local SSD) and `unified`.
7676
Updates to this field will recreate a new resource.
77+
78+
~> **Important:** Snapshots of volumes with type `b_ssd` (Block SSD) are deprecated and cannot be managed using the `scaleway_instance_snapshot` resource anymore. Please use the `scaleway_block_snapshot` resource instead.
79+
If you want to migrate existing snapshots, you can visit [this page](https://www.scaleway.com/en/docs/instances/how-to/migrate-volumes-snapshots-to-sbs/) for more information.
80+
7781
- `name` - (Optional) The name of the snapshot. If not provided it will be randomly generated.
7882
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which
7983
the snapshot should be created.

docs/resources/instance_volume.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ resource "scaleway_instance_volume" "server_volume" {
2222

2323
The following arguments are supported:
2424

25-
- `type` - (Required) The type of the volume. The possible values are: `b_ssd` (Block SSD), `l_ssd` (Local SSD), `scratch` (Local Scratch SSD).
25+
- `type` - (Required) The type of the volume. The possible values are: `l_ssd` (Local SSD), `scratch` (Local Scratch SSD).
26+
27+
~> **Important:** Volumes with type `b_ssd` (Block SSD) are deprecated and cannot be managed using the `scaleway_instance_volume` resource anymore. Please use the `scaleway_block_volume` resource instead.
28+
If you want to migrate existing volumes, you can visit [this page](https://www.scaleway.com/en/docs/instances/how-to/migrate-volumes-snapshots-to-sbs/) for more information.
29+
2630
- `size_in_gb` - (Optional) The size of the volume. Only one of `size_in_gb` and `from_snapshot_id` should be specified.
2731
- `from_snapshot_id` - (Optional) If set, the new volume will be created from this snapshot. Only one of `size_in_gb` and `from_snapshot_id` should be specified.
2832
- `name` - (Optional) The name of the volume. If not provided it will be randomly generated.

internal/services/applesilicon/server.go

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ package applesilicon
22

33
import (
44
"context"
5+
"fmt"
56
"time"
67

8+
"github.com/hashicorp/go-cty/cty"
79
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
911
applesilicon "github.com/scaleway/scaleway-sdk-go/api/applesilicon/v1alpha1"
12+
ipamAPI "github.com/scaleway/scaleway-sdk-go/api/ipam/v1"
1013
"github.com/scaleway/scaleway-sdk-go/scw"
1114
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
1215
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
1316
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
1417
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
1518
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
19+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/ipam"
1620
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
1721
"github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
1822
)
@@ -112,6 +116,26 @@ func ResourceServer() *schema.Resource {
112116
Description: "IPv4 address of the server",
113117
Computed: true,
114118
},
119+
"private_ips": {
120+
Type: schema.TypeList,
121+
Computed: true,
122+
Optional: true,
123+
Description: "List of private IPv4 and IPv6 addresses associated with the server",
124+
Elem: &schema.Resource{
125+
Schema: map[string]*schema.Schema{
126+
"id": {
127+
Type: schema.TypeString,
128+
Computed: true,
129+
Description: "The ID of the IP address resource",
130+
},
131+
"address": {
132+
Type: schema.TypeString,
133+
Computed: true,
134+
Description: "The private IP address",
135+
},
136+
},
137+
},
138+
},
115139
"vnc_url": {
116140
Type: schema.TypeString,
117141
Description: "VNC url use to connect remotely to the desktop GUI",
@@ -262,7 +286,56 @@ func ResourceAppleSiliconServerRead(ctx context.Context, d *schema.ResourceData,
262286

263287
_ = d.Set("private_network", flattenPrivateNetworks(pnRegion, listPrivateNetworks.ServerPrivateNetworks))
264288

265-
return nil
289+
privateNetworkIDs := make([]string, 0, listPrivateNetworks.TotalCount)
290+
for _, pn := range listPrivateNetworks.ServerPrivateNetworks {
291+
privateNetworkIDs = append(privateNetworkIDs, pn.PrivateNetworkID)
292+
}
293+
294+
diags := diag.Diagnostics{}
295+
allPrivateIPs := make([]map[string]interface{}, 0, listPrivateNetworks.TotalCount)
296+
authorized := true
297+
298+
for _, privateNetworkID := range privateNetworkIDs {
299+
resourceType := ipamAPI.ResourceTypeAppleSiliconPrivateNic
300+
opts := &ipam.GetResourcePrivateIPsOptions{
301+
ResourceType: &resourceType,
302+
PrivateNetworkID: &privateNetworkID,
303+
ProjectID: &res.ProjectID,
304+
}
305+
306+
privateIPs, err := ipam.GetResourcePrivateIPs(ctx, m, pnRegion, opts)
307+
308+
switch {
309+
case err == nil:
310+
allPrivateIPs = append(allPrivateIPs, privateIPs...)
311+
case httperrors.Is403(err):
312+
authorized = false
313+
314+
diags = append(diags, diag.Diagnostic{
315+
Severity: diag.Warning,
316+
Summary: "Unauthorized to read server's private IPs, please check your IAM permissions",
317+
Detail: err.Error(),
318+
AttributePath: cty.GetAttrPath("private_ips"),
319+
})
320+
default:
321+
diags = append(diags, diag.Diagnostic{
322+
Severity: diag.Warning,
323+
Summary: fmt.Sprintf("Unable to get private IP for server %q", res.Name),
324+
Detail: err.Error(),
325+
AttributePath: cty.GetAttrPath("private_ips"),
326+
})
327+
}
328+
329+
if !authorized {
330+
break
331+
}
332+
}
333+
334+
if authorized {
335+
_ = d.Set("private_ips", allPrivateIPs)
336+
}
337+
338+
return diags
266339
}
267340

268341
func ResourceAppleSiliconServerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {

internal/services/applesilicon/server_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ func TestAccServer_EnableVPC(t *testing.T) {
136136
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "deletable_at"),
137137
resource.TestCheckResourceAttrPair("scaleway_apple_silicon_server.main", "private_network.0.id", "scaleway_vpc_private_network.pn01", "id"),
138138
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "vpc_status", "vpc_enabled"),
139+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "private_ips.0.id"),
140+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "private_ips.0.address"),
141+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "private_ips.1.id"),
142+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "private_ips.1.address"),
139143
),
140144
},
141145
{
@@ -182,6 +186,14 @@ func TestAccServer_EnableVPC(t *testing.T) {
182186
resource.TestCheckResourceAttrPair("scaleway_apple_silicon_server.main", "private_network.0.id", "scaleway_vpc_private_network.pn01", "id"),
183187
resource.TestCheckResourceAttrPair("scaleway_apple_silicon_server.main", "private_network.1.id", "scaleway_vpc_private_network.pn02", "id"),
184188
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "vpc_status", "vpc_enabled"),
189+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "private_ips.0.id"),
190+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "private_ips.0.address"),
191+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "private_ips.1.id"),
192+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "private_ips.1.address"),
193+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "private_ips.2.id"),
194+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "private_ips.2.address"),
195+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "private_ips.3.id"),
196+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "private_ips.3.address"),
185197
),
186198
},
187199
{

0 commit comments

Comments
 (0)