Skip to content

Commit 1cd8d76

Browse files
Laure-diprotobuf-ci-cd
andauthored
feat(baremetal): support protected server (#3251)
* feat(baremetal): support protected feature fix(domain): handle root zone ID without leading dot (#3208) fix test fix lint Co-authored-by: protobuf-ci-cd <[email protected]> * fix(baremetal): typo and update doc * fix(baremetal): typo and update doc * test(baremetal): update cassettes --------- Co-authored-by: protobuf-ci-cd <[email protected]>
1 parent c10d387 commit 1cd8d76

File tree

3 files changed

+3480
-477
lines changed

3 files changed

+3480
-477
lines changed

docs/resources/baremetal_server.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ The following arguments are supported:
305305
- `ipam_ip_ids` - (Optional) List of IPAM IP IDs to assign to the server in the requested private network.
306306
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the server should be created.
307307
- `partitioning` (Optional) The partitioning schema in JSON format
308+
- `protected` - (Optional) Set to true to activate server protection option.
308309
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the server is associated with.
309310

310311

internal/services/baremetal/server.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ If this behaviour is wanted, please set 'reinstall_on_ssh_key_changes' argument
148148
ValidateFunc: validation.StringLenBetween(0, 255),
149149
Description: "Some description to associate to the server, max 255 characters",
150150
},
151+
"protected": {
152+
Type: schema.TypeBool,
153+
Optional: true,
154+
Default: false,
155+
Description: "If true, the baremetal server is protected against accidental deletion via the Scaleway API.",
156+
},
151157
"tags": {
152158
Type: schema.TypeList,
153159
Elem: &schema.Schema{
@@ -357,6 +363,7 @@ func ResourceServerCreate(ctx context.Context, d *schema.ResourceData, m any) di
357363
Description: d.Get("description").(string),
358364
OfferID: offerID.ID,
359365
Tags: types.ExpandStrings(d.Get("tags")),
366+
Protected: d.Get("protected").(bool),
360367
}
361368

362369
partitioningSchema := baremetal.Schema{}
@@ -505,6 +512,7 @@ func ResourceServerRead(ctx context.Context, d *schema.ResourceData, m any) diag
505512
_ = d.Set("ips", flattenIPs(server.IPs))
506513
_ = d.Set("ipv4", flattenIPv4s(server.IPs))
507514
_ = d.Set("ipv6", flattenIPv6s(server.IPs))
515+
_ = d.Set("protected", server.Protected)
508516

509517
if server.Install != nil {
510518
_ = d.Set("os", zonal.NewIDString(server.Zone, os.ID))
@@ -701,6 +709,11 @@ func ResourceServerUpdate(ctx context.Context, d *schema.ResourceData, m any) di
701709
hasChanged = true
702710
}
703711

712+
if d.HasChange("protected") {
713+
req.Protected = types.ExpandBoolPtr(d.Get("protected").(bool))
714+
hasChanged = true
715+
}
716+
704717
if hasChanged {
705718
_, err = api.UpdateServer(req, scw.WithContext(ctx))
706719
if err != nil {

internal/services/baremetal/testdata/partition-schema-data-source-without-swap-and-extra-part.cassette.yaml

Lines changed: 3466 additions & 477 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)