Azure Bicep:如果属性不存在,则设置 null 值



我正在通过bicep部署azure更新管理服务的时间表。我的代码如下:

param parSchedules array = [
{
name: 'mysched1'
monthlyOccurrencesDay: null
monthlyOccurrencesOccurence: null
DaysOfWeek: 'Wednesday'
StartTime: '${parBaseTimeForUpdateSchedules}T19:00:00'
tag: {
Update: [
'tag1'
]
}
}
{
name: 'mysched2'
monthlyOccurrencesDay: 'Wednesday'
monthlyOccurrencesOccurence: 1
DaysOfWeek: 'Wednesday'
StartTime: '${parBaseTimeForUpdateSchedules}T07:00:00'
tag: {
Update: [
'tag2'
]
}
}
]

resource resUpdateschedule 'Microsoft.Automation/automationAccounts/softwareUpdateConfigurations@2019-06-01' = [for schedule in parSchedules: {
name: schedule.name
parent: resAutomationAccount
properties: {
scheduleInfo: {
advancedSchedule: {
monthlyOccurrences: [
{
day: schedule.monthlyOccurrencesDay
occurrence: schedule.monthlyOccurrencesOccurence
}
]
weekDays: [
schedule.DaysOfWeek
]
}
description: ''
frequency: 'Week'
interval: 1
isEnabled: true
startTime: schedule.StartTime
timeZone: 'UTC'
}
updateConfiguration: {
duration: 'PT2H'
operatingSystem: 'Windows'
targets: {
azureQueries: [
{
locations: [
parLocation
]
scope: [
subscription().id
]
tagSettings: {
tags: schedule.tag
}
}
]
}
windows: {
includedUpdateClassifications: 'Critical, Security'
rebootSetting: 'IfRequired'
}
}
}
}]

由于monthlyOccurrencesDay和monthlyoccurrencesOccurrence不接受null值,因此我收到了此错误。因此,我想要的是能够通过循环相同的资源来使用包含不同类型计划的相同列表(有和没有monthlyOccurrencesOccurrence(。类似于,如果monthlyOccurrencesOccurrence的值为null,则不应考虑此属性这可能吗?

您应该能够有条件地设置每月发生的次数,如下所示:

resource resUpdateschedule 'Microsoft.Automation/automationAccounts/softwareUpdateConfigurations@2019-06-01' = [for schedule in parSchedules: {
name: schedule.name
...
properties: {
scheduleInfo: {
advancedSchedule: {
monthlyOccurrences: schedule.monthlyOccurrencesOccurence != null ? [
{
day: schedule.monthlyOccurrencesDay
occurrence: schedule.monthlyOccurrencesOccurence
}
] : []
...
}
...
}
...
}
}]

最新更新