Skip to content

Commit 6cddf65

Browse files
Laure-didependabot[bot]remyleonejremy42Codelax
authored
feat(apple-silicon): add support vpc (#2875)
* feat(apple-silicon): add support vpc * add tests * add documentation * fix tests * feat(apple-silicon): add support vpc * add test vpc * tests * fix part of tests * manage updating vpc enable update * chore(deps): bump github.com/aws/smithy-go from 1.22.1 to 1.22.2 (#2892) Bumps [github.com/aws/smithy-go](https://github.com/aws/smithy-go) from 1.22.1 to 1.22.2. - [Release notes](https://github.com/aws/smithy-go/releases) - [Changelog](https://github.com/aws/smithy-go/blob/main/CHANGELOG.md) - [Commits](aws/smithy-go@v1.22.1...v1.22.2) --- updated-dependencies: - dependency-name: github.com/aws/smithy-go dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rémy Léone <[email protected]> * chore: bump sdk go (#2880) * chore: bump sdk go * update cassettes rdb * update cassettes billing * update cassettes account * update cassettes account * update cassettes block * update cassettes container * update cassettes flexibleip * update cassette iam * update cassette function * update cassette function * update cassette iot * update cassette webhosting * fix: updated cassettes ipam * fix: updated cassettes redis * fix: updated cassettes lb * fix: updated cassettes sdb * fix: updated cassettes vpc * fix: updated cassettes vpcgw * fix: updated cassettes k8s * fix: updated cassettes vpc one subnet * fix: updated cassettes vpc default name * fix: updated cassettes container * fix: updated cassettes container token basic * fix: updated cassettes function * fix: updated cassettes jobs * fix: updated cassettes vpcgw * fix: updated cassettes vpc * update cassettes instance * bump container token test * bump function token test * fix 500 vpc * fix 500 vpc * fix 412 redis * fix 500 instance * fix 500 ipam * fix 500 k8s * fix ipam cassettes * fix provider cassette * fix provider cassette * fix provider cassette * fix provider TestAccDataSourceProject_Default * chore: go mod tidy * chore: remove downgrade testify --------- Co-authored-by: Jules Casteran <[email protected]> Co-authored-by: Rémy Léone <[email protected]> * commit after rebase * fix tests * tests * manage updating vpc enable update * add waiter terminal state vpc_enable * fix tests enabled vpc with update * update test disable vpc_option * fix test enable-disable * go mod tidy * fix golangci-lint * update test * update cassettes * remove ireturn linter * rollback change mnq --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rémy Léone <[email protected]> Co-authored-by: Jonathan R <[email protected]> Co-authored-by: Jules Casteran <[email protected]>
1 parent b1b12fd commit 6cddf65

File tree

12 files changed

+9856
-208
lines changed

12 files changed

+9856
-208
lines changed

docs/resources/apple_silicon.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The following arguments are supported:
3434

3535
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the server is
3636
associated with.
37+
- `enable_vpc` - (Optional, Default: false): Enables the VPC option when set to true.
3738

3839
## Attributes Reference
3940

@@ -50,6 +51,7 @@ In addition to all arguments above, the following attributes are exported:
5051
- `updated_at` - The date and time of the last update of the Apple Silicon server.
5152
- `deleted_at` - The minimal date and time on which you can delete this server due to Apple licence.
5253
- `organization_id` - The organization ID the server is associated with.
54+
- `vpc_status` - The current status of the VPC option.
5355

5456
## Import
5557

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ require (
2828
github.com/nats-io/jwt/v2 v2.7.3
2929
github.com/nats-io/nats.go v1.38.0
3030
github.com/robfig/cron/v3 v3.0.1
31-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20250117133139-e360c98f921d
31+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250206152403-1eed2f2ce9d3
3232
github.com/stretchr/testify v1.10.0
3333
golang.org/x/crypto v0.32.0
3434
gopkg.in/dnaeon/go-vcr.v3 v3.2.0
@@ -125,9 +125,9 @@ require (
125125
go.opentelemetry.io/otel/trace v1.31.0 // indirect
126126
golang.org/x/mod v0.22.0 // indirect
127127
golang.org/x/net v0.34.0 // indirect
128-
golang.org/x/sync v0.10.0 // indirect
128+
golang.org/x/sync v0.11.0 // indirect
129129
golang.org/x/sys v0.29.0 // indirect
130-
golang.org/x/text v0.21.0 // indirect
130+
golang.org/x/text v0.22.0 // indirect
131131
golang.org/x/time v0.3.0 // indirect
132132
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
133133
google.golang.org/appengine v1.6.8 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXq
280280
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
281281
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
282282
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
283-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20250117133139-e360c98f921d h1:npDtKGreHq1EA6DoHo18YG25bsvZVlo4XlNm822GZ7A=
284-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30.0.20250117133139-e360c98f921d/go.mod h1:kzh+BSAvpoyHHdHBCDhmSWtBc1NbLMZ2lWHqnBoxFks=
283+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250206152403-1eed2f2ce9d3 h1:wNQbwsFYaWiqTRtAgO5uroCTsS0o8FPGdI/x4hCJqtM=
284+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250206152403-1eed2f2ce9d3/go.mod h1:792k1RTU+5JeMXm35/e2Wgp71qPH/DmDoZrRc+EFZDk=
285285
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
286286
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
287287
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
@@ -370,8 +370,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
370370
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
371371
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
372372
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
373-
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
374-
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
373+
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
374+
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
375375
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
376376
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
377377
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -401,8 +401,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
401401
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
402402
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
403403
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
404-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
405-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
404+
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
405+
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
406406
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
407407
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
408408
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

internal/services/applesilicon/clients.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,14 @@ func NewAPIWithZoneAndID(m interface{}, id string) (*applesilicon.API, scw.Zone,
3131

3232
return asAPI, zone, ID, nil
3333
}
34+
35+
func newPrivateNetworkAPIWithZone(d *schema.ResourceData, m interface{}) (*applesilicon.PrivateNetworkAPI, scw.Zone, error) {
36+
privateNetworkAPI := applesilicon.NewPrivateNetworkAPI(meta.ExtractScwClient(m))
37+
38+
zone, err := meta.ExtractZone(d, m)
39+
if err != nil {
40+
return nil, "", err
41+
}
42+
43+
return privateNetworkAPI, zone, nil
44+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package applesilicon
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
applesilicon "github.com/scaleway/scaleway-sdk-go/api/applesilicon/v1alpha1"
8+
"github.com/scaleway/scaleway-sdk-go/scw"
9+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
10+
)
11+
12+
func detachAllPrivateNetworkFromServer(ctx context.Context, d *schema.ResourceData, m interface{}, serverID string) error {
13+
privateNetworkAPI, zone, err := newPrivateNetworkAPIWithZone(d, m)
14+
if err != nil {
15+
return err
16+
}
17+
18+
listPrivateNetwork, err := privateNetworkAPI.ListServerPrivateNetworks(&applesilicon.PrivateNetworkAPIListServerPrivateNetworksRequest{
19+
Zone: zone,
20+
ServerID: &serverID,
21+
}, scw.WithContext(ctx))
22+
if err != nil {
23+
return err
24+
}
25+
26+
for _, pn := range listPrivateNetwork.ServerPrivateNetworks {
27+
err := privateNetworkAPI.DeleteServerPrivateNetwork(&applesilicon.PrivateNetworkAPIDeleteServerPrivateNetworkRequest{
28+
Zone: zone,
29+
ServerID: serverID,
30+
PrivateNetworkID: pn.PrivateNetworkID,
31+
}, scw.WithContext(ctx))
32+
if err != nil {
33+
return err
34+
}
35+
}
36+
37+
_, err = waitForAppleSiliconPrivateNetworkServer(ctx, privateNetworkAPI, zone, serverID, d.Timeout(schema.TimeoutDelete))
38+
if err != nil && !httperrors.Is404(err) {
39+
return err
40+
}
41+
42+
return nil
43+
}

internal/services/applesilicon/server.go

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import (
99
applesilicon "github.com/scaleway/scaleway-sdk-go/api/applesilicon/v1alpha1"
1010
"github.com/scaleway/scaleway-sdk-go/scw"
1111
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
12+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
1213
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
14+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
1315
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
1416
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
17+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
1518
)
1619

1720
func ResourceServer() *schema.Resource {
@@ -41,6 +44,61 @@ func ResourceServer() *schema.Resource {
4144
Required: true,
4245
ForceNew: true,
4346
},
47+
"enable_vpc": {
48+
Type: schema.TypeBool,
49+
Optional: true,
50+
Default: false,
51+
Description: "Whether or not to enable VPC access",
52+
},
53+
"private_network": {
54+
Type: schema.TypeSet,
55+
Optional: true,
56+
Description: "The private networks to attach to the server",
57+
Elem: &schema.Resource{
58+
Schema: map[string]*schema.Schema{
59+
"id": {
60+
Type: schema.TypeString,
61+
Description: "The private network ID",
62+
Required: true,
63+
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
64+
StateFunc: func(i interface{}) string {
65+
return locality.ExpandID(i.(string))
66+
},
67+
},
68+
"ipam_ip_ids": {
69+
Type: schema.TypeList,
70+
Optional: true,
71+
Computed: true,
72+
Elem: &schema.Schema{
73+
Type: schema.TypeString,
74+
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),
75+
},
76+
Description: "List of IPAM IP IDs to attach to the server",
77+
},
78+
// computed
79+
"vlan": {
80+
Type: schema.TypeInt,
81+
Computed: true,
82+
Description: "The VLAN ID associated to the private network",
83+
},
84+
"status": {
85+
Type: schema.TypeString,
86+
Computed: true,
87+
Description: "The private network status",
88+
},
89+
"created_at": {
90+
Type: schema.TypeString,
91+
Computed: true,
92+
Description: "The date and time of the creation of the private network",
93+
},
94+
"updated_at": {
95+
Type: schema.TypeString,
96+
Computed: true,
97+
Description: "The date and time of the last update of the private network",
98+
},
99+
},
100+
},
101+
},
44102
// Computed
45103
"ip": {
46104
Type: schema.TypeString,
@@ -72,6 +130,11 @@ func ResourceServer() *schema.Resource {
72130
Computed: true,
73131
Description: "The minimal date and time on which you can delete this server due to Apple licence",
74132
},
133+
"vpc_status": {
134+
Type: schema.TypeString,
135+
Computed: true,
136+
Description: "The VPC status of the server",
137+
},
75138

76139
// Common
77140
"zone": zonal.Schema(),
@@ -91,6 +154,7 @@ func ResourceAppleSiliconServerCreate(ctx context.Context, d *schema.ResourceDat
91154
Name: types.ExpandOrGenerateString(d.Get("name"), "m1"),
92155
Type: d.Get("type").(string),
93156
ProjectID: d.Get("project_id").(string),
157+
EnableVpc: d.Get("enable_vpc").(bool),
94158
}
95159

96160
res, err := asAPI.CreateServer(createReq, scw.WithContext(ctx))
@@ -105,6 +169,25 @@ func ResourceAppleSiliconServerCreate(ctx context.Context, d *schema.ResourceDat
105169
return diag.FromErr(err)
106170
}
107171

172+
if pn, ok := d.GetOk("private_network"); ok {
173+
privateNetworkAPI := applesilicon.NewPrivateNetworkAPI(meta.ExtractScwClient(m))
174+
req := &applesilicon.PrivateNetworkAPISetServerPrivateNetworksRequest{
175+
Zone: zone,
176+
ServerID: res.ID,
177+
PerPrivateNetworkIpamIPIDs: expandPrivateNetworks(pn),
178+
}
179+
180+
_, err := privateNetworkAPI.SetServerPrivateNetworks(req, scw.WithContext(ctx))
181+
if err != nil {
182+
return diag.FromErr(err)
183+
}
184+
185+
_, err = waitForAppleSiliconPrivateNetworkServer(ctx, privateNetworkAPI, zone, res.ID, d.Timeout(schema.TimeoutCreate))
186+
if err != nil {
187+
return diag.FromErr(err)
188+
}
189+
}
190+
108191
return ResourceAppleSiliconServerRead(ctx, d, m)
109192
}
110193

@@ -114,6 +197,8 @@ func ResourceAppleSiliconServerRead(ctx context.Context, d *schema.ResourceData,
114197
return diag.FromErr(err)
115198
}
116199

200+
privateNetworkAPI := applesilicon.NewPrivateNetworkAPI(meta.ExtractScwClient(m))
201+
117202
res, err := asAPI.GetServer(&applesilicon.GetServerRequest{
118203
Zone: zone,
119204
ServerID: ID,
@@ -136,11 +221,26 @@ func ResourceAppleSiliconServerRead(ctx context.Context, d *schema.ResourceData,
136221
_ = d.Set("deletable_at", res.DeletableAt.Format(time.RFC3339))
137222
_ = d.Set("ip", res.IP.String())
138223
_ = d.Set("vnc_url", res.VncURL)
139-
224+
_ = d.Set("vpc_status", res.VpcStatus)
140225
_ = d.Set("zone", res.Zone.String())
141226
_ = d.Set("organization_id", res.OrganizationID)
142227
_ = d.Set("project_id", res.ProjectID)
143228

229+
listPrivateNetworks, err := privateNetworkAPI.ListServerPrivateNetworks(&applesilicon.PrivateNetworkAPIListServerPrivateNetworksRequest{
230+
Zone: res.Zone,
231+
ServerID: &res.ID,
232+
})
233+
if err != nil {
234+
return diag.FromErr(err)
235+
}
236+
237+
pnRegion, err := res.Zone.Region()
238+
if err != nil {
239+
return diag.FromErr(err)
240+
}
241+
242+
_ = d.Set("private_network", flattenPrivateNetworks(pnRegion, listPrivateNetworks.ServerPrivateNetworks))
243+
144244
return nil
145245
}
146246

@@ -150,6 +250,11 @@ func ResourceAppleSiliconServerUpdate(ctx context.Context, d *schema.ResourceDat
150250
return diag.FromErr(err)
151251
}
152252

253+
appleSilisonPrivateNetworkAPI, zonePN, err := newPrivateNetworkAPIWithZone(d, m)
254+
if err != nil {
255+
return diag.FromErr(err)
256+
}
257+
153258
req := &applesilicon.UpdateServerRequest{
154259
Zone: zone,
155260
ServerID: ID,
@@ -159,11 +264,40 @@ func ResourceAppleSiliconServerUpdate(ctx context.Context, d *schema.ResourceDat
159264
req.Name = types.ExpandStringPtr(d.Get("name"))
160265
}
161266

267+
if d.HasChange("enable_vpc") {
268+
enableVpc := d.Get("enable_vpc").(bool)
269+
req.EnableVpc = &enableVpc
270+
}
271+
162272
_, err = asAPI.UpdateServer(req, scw.WithContext(ctx))
163273
if err != nil {
164274
return diag.FromErr(err)
165275
}
166276

277+
err = waitForTerminalVPCState(ctx, asAPI, zone, ID, d.Timeout(schema.TimeoutCreate))
278+
if err != nil {
279+
return diag.FromErr(err)
280+
}
281+
282+
if d.HasChange("private_network") && d.Get("enable_vpc").(bool) {
283+
privateNetwork := d.Get("private_network")
284+
req := &applesilicon.PrivateNetworkAPISetServerPrivateNetworksRequest{
285+
Zone: zonePN,
286+
ServerID: ID,
287+
PerPrivateNetworkIpamIPIDs: expandPrivateNetworks(privateNetwork),
288+
}
289+
290+
_, err := appleSilisonPrivateNetworkAPI.SetServerPrivateNetworks(req, scw.WithContext(ctx))
291+
if err != nil {
292+
return diag.FromErr(err)
293+
}
294+
}
295+
296+
_, err = waitForAppleSiliconPrivateNetworkServer(ctx, appleSilisonPrivateNetworkAPI, zone, ID, d.Timeout(schema.TimeoutCreate))
297+
if err != nil {
298+
return diag.FromErr(err)
299+
}
300+
167301
return ResourceAppleSiliconServerRead(ctx, d, m)
168302
}
169303

@@ -173,6 +307,11 @@ func ResourceAppleSiliconServerDelete(ctx context.Context, d *schema.ResourceDat
173307
return diag.FromErr(err)
174308
}
175309

310+
err = detachAllPrivateNetworkFromServer(ctx, d, m, ID)
311+
if err != nil {
312+
return diag.FromErr(err)
313+
}
314+
176315
err = asAPI.DeleteServer(&applesilicon.DeleteServerRequest{
177316
Zone: zone,
178317
ServerID: ID,

0 commit comments

Comments
 (0)