gpt4 book ai didi

azure 二头肌 : setting a null value if the property doesn't exist

转载 作者:行者123 更新时间:2023-12-03 00:39:56 25 4
gpt4 key购买 nike

我正在通过 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 和monthlyOccurrencesOccurence 不接受空值。所以我想要的是能够通过循环相同的资源来使用包含不同类型的计划的相同列表(有或没有monthlyOccurrencesOccurence)。就像如果monthlyOccurrencesOccurence的值为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
}
] : []
...
}
...
}
...
}
}]

关于 azure 二头肌 : setting a null value if the property doesn't exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73795406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com