user24901975
user24901975

Reputation: 3

BICEP: Creating Azure Automation Account runbook schedule link fails with "bad request"

I am trying to link a schedule to a runbook using bicep. It fails with the error "Bad Request" and give no other information. Can anyone help with what I am doing wrong here?? The schedule and runbook both exist inside the automation account.

I have followed the Azure documentation and examples so I would expect the code to work but I only receive "Bad Request"

param automationAccountName string

resource automation_account 'Microsoft.Automation/automationAccounts@2022-08-08' existing = {
  name: automationAccountName
}

resource job_schedule 'Microsoft.Automation/automationAccounts/jobSchedules@2022-08-08' = {
  name: 'test-schedule-xxxxxxxxxxxxxxxxxxxxxx'
  parent: automation_account
  properties:{
    parameters: {} //scheduleParams
    schedule: {
      name: 'myschedule'
    }
    runbook: {
      name: 'CheckFileExistsTest'
      }
  }
}

Upvotes: 0

Views: 325

Answers (2)

wenbo
wenbo

Reputation: 1506

JobSchedule name must be the 'uuid' string, can not be arbitray. if name is not formated with 'uuid', will throw the error BadRequest without any additional messages.

enter image description here

I have already test at my side, works well.

param automationAccountName string = 'wbautoaccounttest'

param guidValue string = newGuid()

resource automation_account 'Microsoft.Automation/automationAccounts@2023-11-01' existing = {
  name: automationAccountName
}

resource job_schedule 'Microsoft.Automation/automationAccounts/jobSchedules@2023-11-01' = {
  name: guidValue
  parent: automation_account
  properties:{
    parameters: {}
    schedule: {
      name: 'wbtest'
    }
    runbook: {
      name: 'wbtestrunbook'
      }
  }
}

enter image description here

Upvotes: 0

Hussein Jabbar
Hussein Jabbar

Reputation: 1

The Bicep code snippet you provided seems mostly correct, but there are a few potential issues that could be causing the "Bad Request" error:

Missing Runbook ID: When linking a schedule to a runbook in Azure Automation, you need to provide the full resource ID of the runbook, not just its name. You can retrieve the runbook's resource ID using Azure CLI or PowerShell. Incorrect Schedule Name: Ensure that the schedule name you're referencing ('myschedule') matches the name of the schedule you're trying to link to the runbook. Invalid Schedule Parameters: If your runbook expects parameters, you need to provide them in the parameters field of the job schedule resource. Here's an updated version of your Bicep code snippet addressing these points:

param automationAccountName string
param runbookName string
param scheduleName string

resource automationAccount 'Microsoft.Automation/automationAccounts@2022-08-08' existing = {
  name: automationAccountName
}

// Retrieve the runbook resource ID
var runbook = resourceId('Microsoft.Automation/automationAccounts/runbooks', automationAccountName, runbookName)

resource job_schedule 'Microsoft.Automation/automationAccounts/jobSchedules@2022-08-08' = {
  name: '${automationAccountName}/test-schedule-xxxxxxxxxxxxxxxxxxxxxx'
  properties: {
    parameters: {} // Provide parameters here if needed
    schedule: {
      name: scheduleName
    }
    runbook: {
      id: runbook
    }
  }
}

Make sure to replace runbookName and scheduleName parameters with the actual names of your runbook and schedule, respectively. Additionally, ensure that the runbookName parameter matches the name of the runbook you're trying to link to.

Upvotes: 0

Related Questions