Files
terraform-provider-unifi/internal/utils/cidr.go
Mateusz Filipowicz 325d7b7f20 feat: initialize Terraform Plugin Framework (#23)
* feat: initialize Terraform Plugin Framework

* fix docker-compose path for tests

* fix: ensure documentation can be generated with old provider SDK and new plugin framework

* lint
2025-02-24 00:11:41 +01:00

41 lines
612 B
Go

package utils
import (
"fmt"
"net"
)
func CidrValidate(raw interface{}, key string) ([]string, []error) {
v, ok := raw.(string)
if !ok {
return nil, []error{fmt.Errorf("expected string, got %T", raw)}
}
_, _, err := net.ParseCIDR(v)
if err != nil {
return nil, []error{err}
}
return nil, nil
}
func CidrZeroBased(cidr string) string {
_, cidrNet, err := net.ParseCIDR(cidr)
if err != nil {
return ""
}
return cidrNet.String()
}
func CidrOneBased(cidr string) string {
_, cidrNet, err := net.ParseCIDR(cidr)
if err != nil {
return ""
}
cidrNet.IP[3]++
return cidrNet.String()
}