mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-01 02:52:58 +00:00
* chore(deps): update tools | datasource | package | from | to | | ---------- | ------------------------------------------------------------- | ------- | ------- | | go | github.com/golangci/golangci-lint | v1.55.2 | v1.56.2 | | go | go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp | v0.48.0 | v0.49.0 | * fix linter errors Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --------- Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
package validators
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
|
)
|
|
|
|
// MACAddress is a schema validation function for MAC address.
|
|
func MACAddress() schema.SchemaValidateDiagFunc {
|
|
return validation.ToDiagFunc(func(i interface{}, path string) ([]string, []error) {
|
|
v, ok := i.(string)
|
|
|
|
var ws []string
|
|
|
|
var es []error
|
|
|
|
if !ok {
|
|
es = append(es, fmt.Errorf("expected type of %q to be string", path))
|
|
return ws, es
|
|
}
|
|
|
|
if v != "" {
|
|
r := regexp.MustCompile(`^[A-Fa-f0-9]{2}(:[A-Fa-f0-9]{2}){5}$`)
|
|
ok := r.MatchString(v)
|
|
|
|
if !ok {
|
|
es = append(es, fmt.Errorf("expected %q to be a valid MAC address (A0:B1:C2:D3:E4:F5), got %q", path, v))
|
|
return ws, es
|
|
}
|
|
}
|
|
|
|
return ws, es
|
|
})
|
|
}
|