Skip to content

Commit 5b5e0fa

Browse files
committed
feat(apple-silicon): add support public_bandwidth (scaleway#3186)
* feat(apple-silicon): add support public_bandwidth * tests(apple-silicon): update offer * tests(apple-silicon): register cassette
1 parent c14dc5c commit 5b5e0fa

File tree

4 files changed

+962
-330
lines changed

4 files changed

+962
-330
lines changed

docs/resources/apple_silicon_server.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ The following arguments are supported:
3838

3939
- `commitment_type` (Optional, Default: duration_24h): Activate commitment for this server
4040

41+
- `public_bandwidth` (Optional) Configure the available public bandwidth for your server in bits per second. This option may not be available for all offers.
42+
4143
## Attributes Reference
4244

4345
In addition to all arguments above, the following attributes are exported:

internal/services/applesilicon/server.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ func ResourceServer() *schema.Resource {
6161
Description: "The commitment period of the server",
6262
ValidateDiagFunc: verify.ValidateEnum[applesilicon.CommitmentType](),
6363
},
64+
"public_bandwidth": {
65+
Type: schema.TypeInt,
66+
Optional: true,
67+
Computed: true,
68+
Description: "The public bandwidth of the server in bits per second",
69+
},
6470
"private_network": {
6571
Type: schema.TypeSet,
6672
Optional: true,
@@ -198,6 +204,11 @@ func ResourceAppleSiliconServerCreate(ctx context.Context, d *schema.ResourceDat
198204
ProjectID: d.Get("project_id").(string),
199205
EnableVpc: d.Get("enable_vpc").(bool),
200206
CommitmentType: applesilicon.CommitmentType(d.Get("commitment").(string)),
207+
Zone: zone,
208+
}
209+
210+
if bandwidth, ok := d.GetOk("public_bandwidth"); ok {
211+
createReq.PublicBandwidthBps = *types.ExpandUint64Ptr(bandwidth)
201212
}
202213

203214
res, err := asAPI.CreateServer(createReq, scw.WithContext(ctx))
@@ -270,6 +281,8 @@ func ResourceAppleSiliconServerRead(ctx context.Context, d *schema.ResourceData,
270281
_ = d.Set("project_id", res.ProjectID)
271282
_ = d.Set("password", res.SudoPassword)
272283
_ = d.Set("username", res.SSHUsername)
284+
_ = d.Set("public_bandwidth", int(res.PublicBandwidthBps))
285+
_ = d.Set("zone", res.Zone)
273286

274287
listPrivateNetworks, err := privateNetworkAPI.ListServerPrivateNetworks(&applesilicon.PrivateNetworkAPIListServerPrivateNetworksRequest{
275288
Zone: res.Zone,
@@ -367,6 +380,11 @@ func ResourceAppleSiliconServerUpdate(ctx context.Context, d *schema.ResourceDat
367380
req.EnableVpc = &enableVpc
368381
}
369382

383+
if d.HasChange("public_bandwidth") {
384+
publicBandwidth := types.ExpandUint64Ptr(d.Get("public_bandwidth"))
385+
req.PublicBandwidthBps = publicBandwidth
386+
}
387+
370388
_, err = asAPI.UpdateServer(req, scw.WithContext(ctx))
371389
if err != nil {
372390
return diag.FromErr(err)

internal/services/applesilicon/server_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,35 @@ func TestAccServer_Basic(t *testing.T) {
2424
Config: `
2525
resource scaleway_apple_silicon_server main {
2626
name = "TestAccServerBasic"
27-
type = "M2-M"
27+
type = "M4-M"
28+
public_bandwidth = 1000000000
2829
}
2930
`,
3031
Check: resource.ComposeTestCheckFunc(
3132
isServerPresent(tt, "scaleway_apple_silicon_server.main"),
3233
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "name", "TestAccServerBasic"),
33-
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "type", "M2-M"),
34+
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "type", "M4-M"),
35+
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "public_bandwidth", "1000000000"),
36+
// Computed
37+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "ip"),
38+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "vnc_url"),
39+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "created_at"),
40+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "deletable_at"),
41+
),
42+
},
43+
{
44+
Config: `
45+
resource scaleway_apple_silicon_server main {
46+
name = "TestAccServerBasic"
47+
type = "M4-M"
48+
public_bandwidth = 2000000000
49+
}
50+
`,
51+
Check: resource.ComposeTestCheckFunc(
52+
isServerPresent(tt, "scaleway_apple_silicon_server.main"),
53+
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "name", "TestAccServerBasic"),
54+
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "type", "M4-M"),
55+
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "public_bandwidth", "2000000000"),
3456
// Computed
3557
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "ip"),
3658
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "vnc_url"),

0 commit comments

Comments
 (0)