Hi,
You can try some logic like the one below. It is not the full policy code, but I am sure you can figure it out depending on your requirements. Effect will be AuditIfNotExists.
"if": {
"field": "type",
"equals": "Microsoft.Insights/autoscaleSettings"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Insights/diagnosticSettings",
"existenceCondition": {
"count": {
"field": "Microsoft.Insights/diagnosticSettings/logs[*]",
"where": {
"anyOf": [
{
"allOf": [
{
"field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.enabled",
"equals": "true"
},
{
"anyOf": [
{
"field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.days",
"equals": "0"
},
{
"value": "[padLeft(current('Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.days'), 3, '0')]",
"greaterOrEquals": "[padLeft(parameters('requiredRetentionDays'), 3, '0')]"
}
]
},
{
"field": "Microsoft.Insights/diagnosticSettings/logs.enabled",
"equals": "true"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Insights/diagnosticSettings/logs.enabled",
"equals": "true"
},
{
"anyOf": [
{
"field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.enabled",
"notEquals": "true"
},
{
"field": "Microsoft.Insights/diagnosticSettings/storageAccountId",
"exists": false
}
]
}
]
}
]
}
},
"greaterOrEquals": 1
}
Please "Accept the answer" if the information helped you. This will help us and others in the community as well.