diff --git a/docs/resources/apple_silicon_server.md b/docs/resources/apple_silicon_server.md index 5aa7a9305b..86f72baee6 100644 --- a/docs/resources/apple_silicon_server.md +++ b/docs/resources/apple_silicon_server.md @@ -36,6 +36,8 @@ The following arguments are supported: associated with. - `enable_vpc` - (Optional, Default: false): Enables the VPC option when set to true. +- `commitment_type` (Optional, Default: duration_24h): Activate commitment for this server + ## Attributes Reference In addition to all arguments above, the following attributes are exported: diff --git a/internal/services/applesilicon/server.go b/internal/services/applesilicon/server.go index 12f563d388..846708ab78 100644 --- a/internal/services/applesilicon/server.go +++ b/internal/services/applesilicon/server.go @@ -50,6 +50,13 @@ func ResourceServer() *schema.Resource { Default: false, Description: "Whether or not to enable VPC access", }, + "commitment": { + Type: schema.TypeString, + Optional: true, + Default: "duration_24h", + Description: "The commitment period of the server", + ValidateDiagFunc: verify.ValidateEnum[applesilicon.CommitmentType](), + }, "private_network": { Type: schema.TypeSet, Optional: true, @@ -162,10 +169,11 @@ func ResourceAppleSiliconServerCreate(ctx context.Context, d *schema.ResourceDat } createReq := &applesilicon.CreateServerRequest{ - Name: types.ExpandOrGenerateString(d.Get("name"), "m1"), - Type: d.Get("type").(string), - ProjectID: d.Get("project_id").(string), - EnableVpc: d.Get("enable_vpc").(bool), + Name: types.ExpandOrGenerateString(d.Get("name"), "m1"), + Type: d.Get("type").(string), + ProjectID: d.Get("project_id").(string), + EnableVpc: d.Get("enable_vpc").(bool), + CommitmentType: applesilicon.CommitmentType(d.Get("commitment").(string)), } res, err := asAPI.CreateServer(createReq, scw.WithContext(ctx)) @@ -277,6 +285,10 @@ func ResourceAppleSiliconServerUpdate(ctx context.Context, d *schema.ResourceDat req.Name = types.ExpandStringPtr(d.Get("name")) } + if d.HasChange("commitment") { + req.CommitmentType = &applesilicon.CommitmentTypeValue{CommitmentType: applesilicon.CommitmentType(d.Get("commitment").(string))} + } + if d.HasChange("enable_vpc") { enableVpc := d.Get("enable_vpc").(bool) req.EnableVpc = &enableVpc diff --git a/internal/services/applesilicon/server_test.go b/internal/services/applesilicon/server_test.go index fcef3ac184..75bf4e1388 100644 --- a/internal/services/applesilicon/server_test.go +++ b/internal/services/applesilicon/server_test.go @@ -128,6 +128,7 @@ func TestAccServer_EnableVPC(t *testing.T) { isServerPresent(tt, "scaleway_apple_silicon_server.main"), resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "name", "TestAccServerEnableVPC"), resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "type", "M2-M"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "commitment", "duration_24h"), // Computed resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "ip"), resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "vnc_url"), @@ -225,6 +226,61 @@ func TestAccServer_EnableVPC(t *testing.T) { }) } +func TestAccServer_Commitment(t *testing.T) { + t.Skip("can not delete server at the time") + + tt := acctest.NewTestTools(t) + defer tt.Cleanup() + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ProviderFactories: tt.ProviderFactories, + CheckDestroy: isServerDestroyed(tt), + Steps: []resource.TestStep{ + { + Config: ` + + resource scaleway_apple_silicon_server main { + name = "TestAccServerEnableDisableVPC" + type = "M2-M" + } + `, + Check: resource.ComposeTestCheckFunc( + isServerPresent(tt, "scaleway_apple_silicon_server.main"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "name", "TestAccServerEnableDisableVPC"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "type", "M2-M"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "commitment", "duration_24h"), + // Computed + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "ip"), + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "vnc_url"), + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "created_at"), + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "deletable_at"), + ), + }, + { + Config: ` + + resource scaleway_apple_silicon_server main { + name = "TestAccServerEnableDisableVPC" + type = "M2-M" + commitment = "renewed_monthly" + } + `, + Check: resource.ComposeTestCheckFunc( + isServerPresent(tt, "scaleway_apple_silicon_server.main"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "name", "TestAccServerEnableDisableVPC"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "type", "M2-M"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "commitment", "renewed_monthly"), + // Computed + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "ip"), + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "vnc_url"), + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "created_at"), + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "deletable_at"), + ), + }, + }, + }) +} + func isServerPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n]