From c23abb148c3fd43ecdf59fe08f0a16afa745b6e5 Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Wed, 8 Jan 2020 19:48:17 +0000 Subject: [PATCH] Add validation for start_time to resource_policy Signed-off-by: Modular Magician --- google/validation.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/google/validation.go b/google/validation.go index 3a59f006b4..ac8ee03b65 100644 --- a/google/validation.go +++ b/google/validation.go @@ -261,3 +261,16 @@ func StringNotInSlice(invalid []string, ignoreCase bool) schema.SchemaValidateFu return } } + +// Ensure that hourly timestamp strings "HH:MM" have the minutes zeroed out for hourly only inputs +func validateHourlyOnly(val interface{}, key string) (warns []string, errs []error) { + v := val.(string) + parts := strings.Split(v, ":") + if len(parts) != 2 { + errs = append(errs, fmt.Errorf("%q must be in the format HH:00, got: %s", key, v)) + } + if parts[1] != "00" { + errs = append(errs, fmt.Errorf("%q does not allow minutes, it must be in the format HH:00, got: %s", key, v)) + } + return +}