Skip to content

Commit 941d1fd

Browse files
authored
feat(apple-silicon): support monthly commitment (#2977)
* feat(apple-silicon): commitment * tests * remove test file * fix linter * add doc
1 parent 523f0c4 commit 941d1fd

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

docs/resources/apple_silicon_server.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ The following arguments are supported:
3636
associated with.
3737
- `enable_vpc` - (Optional, Default: false): Enables the VPC option when set to true.
3838

39+
- `commitment_type` (Optional, Default: duration_24h): Activate commitment for this server
40+
3941
## Attributes Reference
4042

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

internal/services/applesilicon/server.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ func ResourceServer() *schema.Resource {
5050
Default: false,
5151
Description: "Whether or not to enable VPC access",
5252
},
53+
"commitment": {
54+
Type: schema.TypeString,
55+
Optional: true,
56+
Default: "duration_24h",
57+
Description: "The commitment period of the server",
58+
ValidateDiagFunc: verify.ValidateEnum[applesilicon.CommitmentType](),
59+
},
5360
"private_network": {
5461
Type: schema.TypeSet,
5562
Optional: true,
@@ -162,10 +169,11 @@ func ResourceAppleSiliconServerCreate(ctx context.Context, d *schema.ResourceDat
162169
}
163170

164171
createReq := &applesilicon.CreateServerRequest{
165-
Name: types.ExpandOrGenerateString(d.Get("name"), "m1"),
166-
Type: d.Get("type").(string),
167-
ProjectID: d.Get("project_id").(string),
168-
EnableVpc: d.Get("enable_vpc").(bool),
172+
Name: types.ExpandOrGenerateString(d.Get("name"), "m1"),
173+
Type: d.Get("type").(string),
174+
ProjectID: d.Get("project_id").(string),
175+
EnableVpc: d.Get("enable_vpc").(bool),
176+
CommitmentType: applesilicon.CommitmentType(d.Get("commitment").(string)),
169177
}
170178

171179
res, err := asAPI.CreateServer(createReq, scw.WithContext(ctx))
@@ -277,6 +285,10 @@ func ResourceAppleSiliconServerUpdate(ctx context.Context, d *schema.ResourceDat
277285
req.Name = types.ExpandStringPtr(d.Get("name"))
278286
}
279287

288+
if d.HasChange("commitment") {
289+
req.CommitmentType = &applesilicon.CommitmentTypeValue{CommitmentType: applesilicon.CommitmentType(d.Get("commitment").(string))}
290+
}
291+
280292
if d.HasChange("enable_vpc") {
281293
enableVpc := d.Get("enable_vpc").(bool)
282294
req.EnableVpc = &enableVpc

internal/services/applesilicon/server_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func TestAccServer_EnableVPC(t *testing.T) {
128128
isServerPresent(tt, "scaleway_apple_silicon_server.main"),
129129
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "name", "TestAccServerEnableVPC"),
130130
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "type", "M2-M"),
131+
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "commitment", "duration_24h"),
131132
// Computed
132133
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "ip"),
133134
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "vnc_url"),
@@ -225,6 +226,61 @@ func TestAccServer_EnableVPC(t *testing.T) {
225226
})
226227
}
227228

229+
func TestAccServer_Commitment(t *testing.T) {
230+
t.Skip("can not delete server at the time")
231+
232+
tt := acctest.NewTestTools(t)
233+
defer tt.Cleanup()
234+
resource.ParallelTest(t, resource.TestCase{
235+
PreCheck: func() { acctest.PreCheck(t) },
236+
ProviderFactories: tt.ProviderFactories,
237+
CheckDestroy: isServerDestroyed(tt),
238+
Steps: []resource.TestStep{
239+
{
240+
Config: `
241+
242+
resource scaleway_apple_silicon_server main {
243+
name = "TestAccServerEnableDisableVPC"
244+
type = "M2-M"
245+
}
246+
`,
247+
Check: resource.ComposeTestCheckFunc(
248+
isServerPresent(tt, "scaleway_apple_silicon_server.main"),
249+
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "name", "TestAccServerEnableDisableVPC"),
250+
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "type", "M2-M"),
251+
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "commitment", "duration_24h"),
252+
// Computed
253+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "ip"),
254+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "vnc_url"),
255+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "created_at"),
256+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "deletable_at"),
257+
),
258+
},
259+
{
260+
Config: `
261+
262+
resource scaleway_apple_silicon_server main {
263+
name = "TestAccServerEnableDisableVPC"
264+
type = "M2-M"
265+
commitment = "renewed_monthly"
266+
}
267+
`,
268+
Check: resource.ComposeTestCheckFunc(
269+
isServerPresent(tt, "scaleway_apple_silicon_server.main"),
270+
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "name", "TestAccServerEnableDisableVPC"),
271+
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "type", "M2-M"),
272+
resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "commitment", "renewed_monthly"),
273+
// Computed
274+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "ip"),
275+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "vnc_url"),
276+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "created_at"),
277+
resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "deletable_at"),
278+
),
279+
},
280+
},
281+
})
282+
}
283+
228284
func isServerPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc {
229285
return func(s *terraform.State) error {
230286
rs, ok := s.RootModule().Resources[n]

0 commit comments

Comments
 (0)