Skip to content

Commit 7b1c59a

Browse files
committed
feat(cockpit): add validate func for retention days
1 parent a14799e commit 7b1c59a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

internal/services/cockpit/source.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
89
"github.com/scaleway/scaleway-sdk-go/api/cockpit/v1"
910
"github.com/scaleway/scaleway-sdk-go/scw"
1011
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
@@ -44,9 +45,10 @@ func ResourceCockpitSource() *schema.Resource {
4445
ValidateDiagFunc: verify.ValidateEnum[cockpit.DataSourceType](),
4546
},
4647
"retention_days": {
47-
Type: schema.TypeInt,
48-
Required: true,
49-
Description: "The number of days to retain data, must be between 1 and 365.",
48+
Type: schema.TypeInt,
49+
Required: true,
50+
ValidateFunc: validation.IntBetween(1, 365),
51+
Description: "The number of days to retain data, must be between 1 and 365.",
5052
},
5153
// computed
5254
"url": {
@@ -166,7 +168,7 @@ func ResourceCockpitSourceUpdate(ctx context.Context, d *schema.ResourceData, me
166168
updateRequest.RetentionDays = &retentionDays
167169
}
168170

169-
if updateRequest.Name != nil || updateRequest.RetentionDays != nil {
171+
if d.HasChange("retention_days") || d.HasChange("name") {
170172
_, err = api.UpdateDataSource(updateRequest, scw.WithContext(ctx))
171173
if err != nil {
172174
return diag.FromErr(err)

0 commit comments

Comments
 (0)