Hello Christophe Humbert,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you would like to evaluate and check if the Cosmos DB are in Continuous Backup Mode.
Your policy is correctly set up to check if the Cosmos DB accounts have the backup policy type set to Continuous. But the non-compliance message suggests that there might be an issue with how the policy is being evaluated or applied.
For this review, there are a few things to check and try as listed below:
- Check that the policy is assigned to the correct scope (e.g., subscription, resource group) where your Cosmos DB accounts are located.
- Policy evaluations can take some time to reflect the correct compliance state. You might want to manually trigger a policy evaluation to see if the compliance state updates correctly.
- Double-check the field path in your policy definition. The path should match exactly with the structure of the resource properties. In your case, it looks correct, but it’s worth verifying against the actual resource properties.
- Make sure that the policy effect is set correctly. Since you are using “Audit”, it should only log the compliance state without enforcing any changes.
This is a slightly modified version of your policy definition for clarity as discussed:
{
"properties": {
"displayName": "Azure Cosmos Backup Definition [test]",
"policyType": "Custom",
"mode": "All",
"description": "This policy enables you to audit that continuous backup is enabled",
"metadata": {
"category": "Cosmos DB"
},
"version": "1.0.0",
"parameters": {
"policyEffect": {
"type": "String",
"metadata": {
"displayName": "Policy Effect",
"description": "The desired effect of the policy."
},
"allowedValues": [
"Audit",
"Disabled"
],
"defaultValue": "Audit"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.DocumentDB/databaseAccounts"
},
{
"field": "Microsoft.DocumentDB/databaseAccounts/backupPolicy.type",
"equals": "Continuous"
}
]
},
"then": {
"effect": "[parameters('policyEffect')]"
}
}
},
"id": "/providers/Microsoft.Management/managementGroups/xxxxxxx/providers/Microsoft.Authorization/policyDefinitions/06899040-902a-4816-aa1f-0db587e207a0",
"type": "Microsoft.Authorization/policyDefinitions",
"name": "06899040-902a-4816-aa1f-0db587e207a0",
"systemData": {
"createdBy": "wwwwwwwwwwww",
"createdByType": "User",
"createdAt": "2024-11-14T14:12:57.15076Z",
"lastModifiedBy": "zzzzzzzz",
"lastModifiedByType": "User",
"lastModifiedAt": "2024-11-14T14:55:59.7193798Z"
}
}
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.