Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/resources/apple_silicon_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 16 additions & 4 deletions internal/services/applesilicon/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions internal/services/applesilicon/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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]
Expand Down
Loading