Azure / Azure/azure-policy

Azure policy to deny creation of second diagnostic setting if the first one already exists.

Open
#1,237 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Open Policy Agent
Stars
1.7k
Forks
1.2k
Avg merge
2d 54m
Merged PRs (30d)
3

Description

Is there a way for Azure policy to deny creation of second diagnostic setting if the first one already exists?

I tried below, but it doesn't seem to work for my use case

> {
"mode": "All",
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Insights/diagnosticSettings"
},
"then": {
"effect": "deny"
}
},
"parameters": {}
}

I don't think we could do the audit policy too since we can't use Microsoft.Insights/diagnosticSettings[*] in the count field.

> {
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Insights/diagnosticSettings"
},
{
"count": {
"field": "Microsoft.Insights/diagnosticSettings[*]",
"where": {
"allOf": [
{
"field": "Microsoft.Insights/diagnosticSettings/workspaceId",
"exists": "true"
}
]
}
},
"greater": 1
}
]
},
"then": {
"effect": "audit"
}
},
"parameters": {}
}

This is erroring out saying

`The 'field' property 'Microsoft.Insights/diagnosticSettings[*]' of the policy rule does not exist as an alias under provider 'Microsoft.Insights'.`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the policy validation error with the two JSON examples in the issue, then review Azure Policy aliases and count-field support for Microsoft.Insights/diagnosticSettings. Done means determining whether this constraint is supported and documenting or implementing a clear path forward.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.