Files
terraform-provider-decort/internal/validators/validator.go

23 lines
554 B
Go
Raw Normal View History

2024-03-26 12:17:33 +03:00
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
}
2024-05-31 14:05:21 +03:00
if total%divisibility != 0 {
2024-03-26 12:17:33 +03:00
errors = append(errors, fmt.Errorf("expected value of %s to be divisible by %d", k, divisibility))
}
return warnings, errors
}
}