Skip to content

Commit e7eadbb

Browse files
william-wtr92remyleoneyfodil
authored
feat(instance): add support for the protected parameter for instances enhancement instance (#3026)
* feat: add support for the protected parameter for instances * fix: indentation * Fix * update lb cassettes * add doc --------- Co-authored-by: Rémy Léone <[email protected]> Co-authored-by: Yacine FODIL <[email protected]>
1 parent 8f95b60 commit e7eadbb

File tree

6 files changed

+575
-559
lines changed

6 files changed

+575
-559
lines changed

docs/resources/instance_server.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ attached to the server. Updates to this field will trigger a stop/start of the s
254254

255255
- `replace_on_type_change` - (Defaults to false) If true, the server will be replaced if `type` is changed. Otherwise, the server will migrate.
256256

257+
- `protected` - (Optional) Set to true to activate server protection option.
258+
257259
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the server should be created.
258260

259261
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the server is associated with.

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module github.com/scaleway/terraform-provider-scaleway/v2
22

33
go 1.24.0
4+
45
require (
56
github.com/aws/aws-sdk-go-v2 v1.36.3
67
github.com/aws/aws-sdk-go-v2/config v1.29.9
@@ -25,7 +26,7 @@ require (
2526
github.com/nats-io/jwt/v2 v2.7.3
2627
github.com/nats-io/nats.go v1.38.0
2728
github.com/robfig/cron/v3 v3.0.1
28-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250320132958-0f59cae533d0
29+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250407124844-38ab1ca8e81d
2930
github.com/stretchr/testify v1.10.0
3031
golang.org/x/crypto v0.36.0
3132
gopkg.in/dnaeon/go-vcr.v3 v3.2.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
296296
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
297297
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
298298
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
299-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250320132958-0f59cae533d0 h1:aqpUaCWx5ta43b9dZv1bMIvUUJTux9Am+S7RmJbiVN8=
300-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.32.0.20250320132958-0f59cae533d0/go.mod h1:792k1RTU+5JeMXm35/e2Wgp71qPH/DmDoZrRc+EFZDk=
299+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250407124844-38ab1ca8e81d h1:EjD1RHPgsTomVw0lKgZu6YHK4ZMSBkSjeFrirnvWBcw=
300+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250407124844-38ab1ca8e81d/go.mod h1:792k1RTU+5JeMXm35/e2Wgp71qPH/DmDoZrRc+EFZDk=
301301
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
302302
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
303303
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=

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,
@@ -384,6 +390,7 @@ func ResourceInstanceServerCreate(ctx context.Context, d *schema.ResourceData, m
384390
SecurityGroup: types.ExpandStringPtr(zonal.ExpandID(d.Get("security_group_id")).ID),
385391
DynamicIPRequired: scw.BoolPtr(d.Get("enable_dynamic_ip").(bool)),
386392
Tags: types.ExpandStrings(d.Get("tags")),
393+
Protected: d.Get("protected").(bool),
387394
}
388395

389396
enableIPv6, ok := d.GetOk("enable_ipv6")
@@ -619,6 +626,7 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m i
619626
_ = d.Set("enable_dynamic_ip", server.DynamicIPRequired)
620627
_ = d.Set("organization_id", server.Organization)
621628
_ = d.Set("project_id", server.Project)
629+
_ = d.Set("protected", server.Protected)
622630

623631
// Image could be empty in an import context.
624632
image := regional.ExpandID(d.Get("image").(string))
@@ -824,6 +832,11 @@ func ResourceInstanceServerUpdate(ctx context.Context, d *schema.ResourceData, m
824832
updateRequest.DynamicIPRequired = scw.BoolPtr(d.Get("enable_dynamic_ip").(bool))
825833
}
826834

835+
if d.HasChange("protected") {
836+
serverShouldUpdate = true
837+
updateRequest.Protected = types.ExpandBoolPtr(d.Get("protected").(bool))
838+
}
839+
827840
if d.HasChanges("additional_volume_ids", "root_volume") {
828841
volumes, err := instanceServerVolumesUpdate(ctx, d, api, zone, isStopped)
829842
if err != nil {

0 commit comments

Comments
 (0)