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
1 change: 1 addition & 0 deletions docs/resources/baremetal_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ The following arguments are supported:
- `ipam_ip_ids` - (Optional) List of IPAM IP IDs to assign to the server in the requested private network.
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the server should be created.
- `partitioning` (Optional) The partitioning schema in JSON format
- `protected` - (Optional) Set to true to activate server protection option.
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the server is associated with.


Expand Down
13 changes: 13 additions & 0 deletions internal/services/baremetal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ If this behaviour is wanted, please set 'reinstall_on_ssh_key_changes' argument
ValidateFunc: validation.StringLenBetween(0, 255),
Description: "Some description to associate to the server, max 255 characters",
},
"protected": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "If true, the baremetal server is protected against accidental deletion via the Scaleway API.",
},
"tags": {
Type: schema.TypeList,
Elem: &schema.Schema{
Expand Down Expand Up @@ -357,6 +363,7 @@ func ResourceServerCreate(ctx context.Context, d *schema.ResourceData, m any) di
Description: d.Get("description").(string),
OfferID: offerID.ID,
Tags: types.ExpandStrings(d.Get("tags")),
Protected: d.Get("protected").(bool),
}

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

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

if d.HasChange("protected") {
req.Protected = types.ExpandBoolPtr(d.Get("protected").(bool))
hasChanged = true
}

if hasChanged {
_, err = api.UpdateServer(req, scw.WithContext(ctx))
if err != nil {
Expand Down

Large diffs are not rendered by default.

Loading