Azure policy to deny adding a second diagnostic setting to any resource if the first diagnostic setting already exists
I tried the below code, but it doesn't seem to have any resource details and it doesn't work
{
"mode": "All",
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Insights/diagnosticSettings"
},
"then": {
"effect": "deny"
}
},
"parameters": {}
}
The Azure policy is as follows: I found out how avoid the addition of two or more diagnostic settings. If at least one diagnostic parameter is already enabled and set to "true," the policy allows it.
If a resource has several diagnostic settings with enabled set to "true," the policy forbids.
Created successfully:
Azure Policy
COUNToperator.