diff --git a/google-beta/resource_compute_resource_policy.go b/google-beta/resource_compute_resource_policy.go index ef17caad1f..b8120727fe 100644 --- a/google-beta/resource_compute_resource_policy.go +++ b/google-beta/resource_compute_resource_policy.go @@ -92,9 +92,10 @@ which cannot be a dash.`, Description: `The number of days between snapshots.`, }, "start_time": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateHourlyOnly, Description: `This must be in UTC format that resolves to one of 00:00, 04:00, 08:00, 12:00, 16:00, or 20:00. For example, both 13:00-5 and 08:00 are valid.`, @@ -118,12 +119,14 @@ both 13:00-5 and 08:00 are valid.`, Description: `The number of hours between snapshots.`, }, "start_time": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateHourlyOnly, Description: `Time within the window to start the operations. -It must be in format "HH:MM", -where HH : [00-23] and MM : [00-00] GMT.`, +It must be in an hourly format "HH:MM", +where HH : [00-23] and MM : [00] GMT. +eg: 21:00`, }, }, }, diff --git a/google-beta/validation.go b/google-beta/validation.go index 3a59f006b4..7ce1ccd209 100644 --- a/google-beta/validation.go +++ b/google-beta/validation.go @@ -261,3 +261,23 @@ 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)) + return + } + 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)) + } + i, err := strconv.Atoi(parts[0]) + if err != nil { + errs = append(errs, fmt.Errorf("%q cannot be parsed, it must be in the format HH:00, got: %s", key, v)) + } else if i < 0 || i > 23 { + errs = append(errs, fmt.Errorf("%q does not specify a valid hour, it must be in the format HH:00 where HH : [00-23], got: %s", key, v)) + } + return +} diff --git a/website/docs/r/compute_resource_policy.html.markdown b/website/docs/r/compute_resource_policy.html.markdown index b704b5c8cd..2ea2df6fe1 100644 --- a/website/docs/r/compute_resource_policy.html.markdown +++ b/website/docs/r/compute_resource_policy.html.markdown @@ -152,8 +152,9 @@ The `hourly_schedule` block supports: * `start_time` - (Required) Time within the window to start the operations. - It must be in format "HH:MM", - where HH : [00-23] and MM : [00-00] GMT. + It must be in an hourly format "HH:MM", + where HH : [00-23] and MM : [00] GMT. + eg: 21:00 The `daily_schedule` block supports: