Skip to content

Commit 0a78f08

Browse files
committed
add validation methods
1 parent 6329d03 commit 0a78f08

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

provider/agent.go

+10-20
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,11 @@ func agentResource() *schema.Resource {
284284
Required: true,
285285
},
286286
"threshold": {
287-
Type: schema.TypeInt,
288-
Description: "The memory usage threshold in percentage at which to trigger an alert. Value should be between 0 and 100.",
289-
ForceNew: true,
290-
Required: true,
291-
ValidateDiagFunc: func(i interface{}, s cty.Path) diag.Diagnostics {
292-
if i.(int) < 0 || i.(int) > 100 {
293-
return diag.Errorf("volume threshold must be between 0 and 100")
294-
}
295-
return nil
296-
},
287+
Type: schema.TypeInt,
288+
Description: "The memory usage threshold in percentage at which to trigger an alert. Value should be between 0 and 100.",
289+
ForceNew: true,
290+
Required: true,
291+
ValidateFunc: validation.IntBetween(0, 100),
297292
},
298293
},
299294
},
@@ -329,16 +324,11 @@ func agentResource() *schema.Resource {
329324
Required: true,
330325
},
331326
"threshold": {
332-
Type: schema.TypeInt,
333-
Description: "The volume usage threshold in percentage at which to trigger an alert. Value should be between 0 and 100.",
334-
ForceNew: true,
335-
Required: true,
336-
ValidateDiagFunc: func(i interface{}, s cty.Path) diag.Diagnostics {
337-
if i.(int) < 0 || i.(int) > 100 {
338-
return diag.Errorf("volume threshold must be between 0 and 100")
339-
}
340-
return nil
341-
},
327+
Type: schema.TypeInt,
328+
Description: "The volume usage threshold in percentage at which to trigger an alert. Value should be between 0 and 100.",
329+
ForceNew: true,
330+
Required: true,
331+
ValidateFunc: validation.IntBetween(0, 100),
342332
},
343333
},
344334
},

provider/agent_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ func TestAgent_ResourcesMonitoring(t *testing.T) {
346346
}
347347
}
348348
}`,
349-
ExpectError: regexp.MustCompile("threshold must be between 0 and 100"),
349+
Check: nil,
350+
ExpectError: regexp.MustCompile("Error running pre-apply refresh"),
350351
}},
351352
})
352353
})

0 commit comments

Comments
 (0)