Skip to content

Commit c37539d

Browse files
committed
feat(apple-silicon): add support public_bandwidth
1 parent 280975a commit c37539d

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
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: 16 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,
@@ -200,6 +206,10 @@ func ResourceAppleSiliconServerCreate(ctx context.Context, d *schema.ResourceDat
200206
CommitmentType: applesilicon.CommitmentType(d.Get("commitment").(string)),
201207
}
202208

209+
if bandwidth, ok := d.GetOk("public_bandwidth"); ok {
210+
createReq.PublicBandwidthBps = uint64(bandwidth.(int))
211+
}
212+
203213
res, err := asAPI.CreateServer(createReq, scw.WithContext(ctx))
204214
if err != nil {
205215
return diag.FromErr(err)
@@ -270,6 +280,7 @@ func ResourceAppleSiliconServerRead(ctx context.Context, d *schema.ResourceData,
270280
_ = d.Set("project_id", res.ProjectID)
271281
_ = d.Set("password", res.SudoPassword)
272282
_ = d.Set("username", res.SSHUsername)
283+
_ = d.Set("public_bandwidth", res.PublicBandwidthBps)
273284

274285
listPrivateNetworks, err := privateNetworkAPI.ListServerPrivateNetworks(&applesilicon.PrivateNetworkAPIListServerPrivateNetworksRequest{
275286
Zone: res.Zone,
@@ -367,6 +378,11 @@ func ResourceAppleSiliconServerUpdate(ctx context.Context, d *schema.ResourceDat
367378
req.EnableVpc = &enableVpc
368379
}
369380

381+
if d.HasChange("public_bandwidth") {
382+
publicBandwidth := uint64(d.Get("public_bandwidth").(int))
383+
req.PublicBandwidthBps = &publicBandwidth
384+
}
385+
370386
_, err = asAPI.UpdateServer(req, scw.WithContext(ctx))
371387
if err != nil {
372388
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)