I am new to azure policy and i am trying to implement azure policy to enforce creation of diagnostic setting on azure resources.
My goal is to achieve below..
- Create a diagnostic settings on resource every time a new resource is created. -- works
- Recreate/modify if diagnostics setting/destination is manually changed or deleted. -- Not working
- Recreate/modify the diagnostics settings at scale when the assignment is recreated with different configuration. -- Not working
This is the policy i am using
"existenceCondition": {
"anyof": [
{
"field": "Microsoft.Insights/diagnosticSettings/logs.enabled",
"equals": "[parameters('logsEnabled')]"
},
{
"field": "Microsoft.Insights/diagnosticSettings/eventHubAuthorizationRuleId",
"equals": "[parameters('eventHubAuthorizationRuleId')]"
},
{
"field": "Microsoft.Insights/diagnosticSettings/eventHubName",
"equals": "[parameters('eventHubName')]"
},
{
"field": "Microsoft.Insights/diagnosticSettings/workspaceId",
"equals": "[parameters('workspaceId')]"
}
]
My goal is to achieve below..
- Create a diagnostic settings on resource every time a new resource is created. -- works
- Recreate/modify if diagnostics setting/destination is manually changed or deleted. -- Not working
- Recreate/modify the diagnostics settings at scale when the assignment is recreated with different configuration. -- Not working
The Azure policy will enable diagnostic settings on newly created resources and will also modify the diagnostic settings if they have been updated or deleted manually.
Policy Assignment:
The policy will make sure that all resources in the active subscription have their diagnostic settings enabled after it has been assigned to the scope.