You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
554 B
23 lines
554 B
package validators
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
)
|
|
|
|
func DivisibleBy(divisibility int) schema.SchemaValidateFunc {
|
|
return func(i interface{}, k string) (warnings []string, errors []error) {
|
|
total, ok := i.(int)
|
|
if !ok {
|
|
errors = append(errors, fmt.Errorf("expected type of %s to be integer", k))
|
|
return warnings, errors
|
|
}
|
|
if total%divisibility != 0 {
|
|
errors = append(errors, fmt.Errorf("expected value of %s to be divisible by %d", k, divisibility))
|
|
}
|
|
|
|
return warnings, errors
|
|
}
|
|
}
|