diff --git a/azurerm/internal/services/automation/resource_arm_automation_schedule.go b/azurerm/internal/services/automation/resource_arm_automation_schedule.go index 406738e1ca9f5..c9c1e6d6b221d 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_schedule.go +++ b/azurerm/internal/services/automation/resource_arm_automation_schedule.go @@ -238,11 +238,19 @@ func resourceArmAutomationScheduleCreateUpdate(d *schema.ResourceData, meta inte properties := parameters.ScheduleCreateOrUpdateProperties //start time can default to now + 7 (5 could be invalid by the time the API is called) + loc, err := time.LoadLocation(timeZone) + if err != nil { + return fmt.Errorf("error parsing timezone timezone %q: %s", timeZone, err) + } if v, ok := d.GetOk("start_time"); ok { t, _ := time.Parse(time.RFC3339, v.(string)) //should be validated by the schema + duration := time.Duration(5) * time.Minute + if t.Sub(time.Now().In(loc)) < duration { + return fmt.Errorf("start_time is %q and should be at least %q in the future", t, duration) + } properties.StartTime = &date.Time{Time: t} } else { - properties.StartTime = &date.Time{Time: time.Now().Add(time.Duration(7) * time.Minute)} + properties.StartTime = &date.Time{Time: time.Now().In(loc).Add(time.Duration(7) * time.Minute)} } if v, ok := d.GetOk("expiry_time"); ok {