Skip to content

Commit 8a8726a

Browse files
authored
feat: add support for the protected parameter for instances
1 parent 410bdbd commit 8a8726a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

internal/services/instance/server.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ func ResourceServer() *schema.Resource {
7373
Description: "The instanceSDK type of the server", // TODO: link to scaleway pricing in the doc
7474
DiffSuppressFunc: dsf.IgnoreCase,
7575
},
76+
"protected": {
77+
Type: schema.TypeBool,
78+
Optional: true,
79+
Default: false,
80+
Description: "If true, the instance is protected against accidental deletion via the Scaleway API.",
81+
},
7682
"replace_on_type_change": {
7783
Type: schema.TypeBool,
7884
Optional: true,
@@ -393,6 +399,7 @@ func ResourceInstanceServerCreate(ctx context.Context, d *schema.ResourceData, m
393399
SecurityGroup: types.ExpandStringPtr(zonal.ExpandID(d.Get("security_group_id")).ID),
394400
DynamicIPRequired: scw.BoolPtr(d.Get("enable_dynamic_ip").(bool)),
395401
Tags: types.ExpandStrings(d.Get("tags")),
402+
Protected: scw.BoolPtr(d.Get("protected").(bool)),
396403
}
397404

398405
enableIPv6, ok := d.GetOk("enable_ipv6")
@@ -628,6 +635,7 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m i
628635
_ = d.Set("enable_dynamic_ip", server.DynamicIPRequired)
629636
_ = d.Set("organization_id", server.Organization)
630637
_ = d.Set("project_id", server.Project)
638+
_ = d.Set("protected", server.Protected)
631639

632640
// Image could be empty in an import context.
633641
image := regional.ExpandID(d.Get("image").(string))
@@ -832,6 +840,11 @@ func ResourceInstanceServerUpdate(ctx context.Context, d *schema.ResourceData, m
832840
serverShouldUpdate = true
833841
updateRequest.DynamicIPRequired = scw.BoolPtr(d.Get("enable_dynamic_ip").(bool))
834842
}
843+
844+
if d.HasChange("protected") {
845+
serverShouldUpdate = true
846+
updateRequest.Protected = scw.BoolPtr(d.Get("protected").(bool))
847+
}
835848

836849
if d.HasChanges("additional_volume_ids", "root_volume") {
837850
volumes, err := instanceServerVolumesUpdate(ctx, d, api, zone, isStopped)

0 commit comments

Comments
 (0)