Azure / bicep-types-az

Bicep type definitions for ARM resources
MIT License
83 stars 26 forks source link

[Microsoft.Automation/automationAccounts/schedules]: Bicep/ARM does not correctly interpret the next start time? #1351

Open DavidAtImpactCubed opened 1 year ago

DavidAtImpactCubed commented 1 year ago

Bicep version 0.14.6

Describe the bug We deploy an automation runbook using Bicep. The schedule is set to execute every date at a fixed time. When deploying, if we deploy before the time of day of the scheduled execution, everything works fine. If we deploy after that time of day, we get the following error in the deployment log: The start time of the schedule must be at least 5 minutes after the time you create the schedule.

This seems wrong - the next scheduled execution is tomorrow, at the specified time of day, not in the past.

I'm not clear on whether this is a Bicep issue (i.e. Bicep should be interpreting the properties provided) or something else in the Azure platform - apologies if this is not the right place to raise this.

To Reproduce Deploy an automation runbook with a schedule as follows:

resource schedule 'Microsoft.Automation/automationAccounts/schedules@2020-01-13-preview' = {
  name: 'Schedule'
  parent: automationAccountResource
  properties: {
    description: ''
    expiryTime: ''
    frequency: 'Day'
    interval: 1
    startTime: '01:00'
    timeZone: 'Europe/London'
  }
  dependsOn: [
    automationAccountResource
  ]
}
audrius-a commented 1 year ago

I'm having the same issue and can't figure out how to set startTime to today or tomorrow depending on whether the deployment is run past the hour.

alex-frankel commented 1 year ago

If a deployment works once and then fails later with no changes, then that is an issue with the resource provider. Can either of you open a support ticket so that the Automation team can take a look?

slavizh commented 1 year ago

schedules is badly written resource. The problem is within the resource itself not Bicep. You can set startTime in the following format YYYY-MM-ddTHH:mm:ss±hh:mm. For example "2023-02-15T09:47:00+02:00". The last is the time zone offset. I believe the offset must match the time zone otherwise you might get weird results. Try that and let me know if it works. When I deploy schedules I usually do not specify startTime at all. That way the start time is time of deployment + 5-10 minutes. Keep in mind that schedules also needs to be unique across all global Azure. So if you try to create schedule with same in another tenant it will fail. Also deleted schedules are kept somewhere for some time and you cannot delete schedule and than re-use the name, at least not for some period of time.

slavizh commented 1 year ago

as Alex mentioned you can open a support case but most likely they will tell you this is by design.

audrius-freemarket commented 1 year ago

I've figured out a work around. Bicep date functions are rather crude so it does look a bit ugly. Apologies if there are any errors as I retyped it to simplify my actual working setup.

param now string = utcNow('yyyy-MM-ddTHH:mm:ss')
param todayDate string = utcNow('yyyy-MM-dd')

var nowTicks = dateTimeToEpoch(now)
var offsetSeconds = 300 // time delay of 5min to allow for deployment delays
var startTime = '01:00:00'

resource schedule 'Microsoft.Automation/automationAccounts/schedules@2022-08-08' = {
  name: 'daily-schedule'
  parent: account
  properties: {
    startTime: dateTimeAdd('${todayDate}T${startTime}', dateTimeToEpoch('${todayDate}T${startTime}') > nowTicks + offsetSeconds ? 'P0D' : 'P1D')
    expiryTime: '9999-12-31T23:59:00+00:00'
    interval: 1
    frequency: 'Day'
    timeZone: 'Europe/London'
  }
}
ghost commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jaspkaur28. Please see https://aka.ms/biceptypesinfo for troubleshooting help.

Issue Details
**Bicep version** 0.14.6 **Describe the bug** We deploy an automation runbook using Bicep. The schedule is set to execute every date at a fixed time. When deploying, if we deploy before the time of day of the scheduled execution, everything works fine. If we deploy after that time of day, we get the following error in the deployment log: ```The start time of the schedule must be at least 5 minutes after the time you create the schedule.``` This seems wrong - the next scheduled execution is tomorrow, at the specified time of day, not in the past. I'm not clear on whether this is a Bicep issue (i.e. Bicep should be interpreting the properties provided) or something else in the Azure platform - apologies if this is not the right place to raise this. **To Reproduce** Deploy an automation runbook with a schedule as follows: ``` resource schedule 'Microsoft.Automation/automationAccounts/schedules@2020-01-13-preview' = { name: 'Schedule' parent: automationAccountResource properties: { description: '' expiryTime: '' frequency: 'Day' interval: 1 startTime: '01:00' timeZone: 'Europe/London' } dependsOn: [ automationAccountResource ] } ```
Author: DavidAtImpactCubed
Assignees: -
Labels: `inaccuracy`, `RP: Microsoft.Automation`, `Service Attention`, `Automation`
Milestone: -