github.com/hashicorp/terraform-plugin-sdk@v1.17.2/helper/validation/uuid.go (about)

     1  package validation
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/go-uuid"
     7  )
     8  
     9  // IsUUID is a ValidateFunc that ensures a string can be parsed as UUID
    10  func IsUUID(i interface{}, k string) (warnings []string, errors []error) {
    11  	v, ok := i.(string)
    12  	if !ok {
    13  		errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
    14  		return
    15  	}
    16  
    17  	if _, err := uuid.ParseUUID(v); err != nil {
    18  		errors = append(errors, fmt.Errorf("expected %q to be a valid UUID, got %v", k, v))
    19  	}
    20  
    21  	return warnings, errors
    22  }