参考回答
If you assign an Azure Policy definition to a scope that includes existing resources, Azure Policy will automatically evaluate those resources to determine if they comply with the newly assigned policy. Here's what happens step-by-step:
1. Initial Compliance Evaluation
Once the policy is assigned, Azure Policy immediately assesses all resources within the scope (e.g., management group, subscription, or resource group) to see if they meet the policy criteria.
Each resource is flagged as either compliant or non-compliant based on whether it adheres to the policy requirements.
The Azure Policy dashboard displays a compliance report, giving you visibility into which resources comply, and which do not.
2. Handling Non-Compliant Resources
For resources flagged as non-compliant, the next steps depend on the policy's effect type:
Audit: Marks resources as non-compliant but doesn't enforce any change. This allows you to monitor compliance without affecting existing configurations.
Deny: Blocks new resources or configuration changes that don't comply with the policy. However, it doesn't apply to existing resources, meaning those already in place will remain as-is but will still be flagged as non-compliant.
DeployIfNotExists: For non-compliant resources, Azure Policy can automatically deploy missing configurations or settings. For example, if a policy requires diagnostic logging and a resource doesn't have it enabled, this effect can automatically enable it.
Modify: Similar to DeployIfNotExists, but this effect modifies existing non-compliant resources to bring them into compliance. For instance, if a resource requires a specific tag, the Modify effect can add it.
3. Ongoing Monitoring
Azure Policy continuously evaluates resources within the scope to detect new non-compliance issues. If configurations change and violate policy requirements, the policy will flag the resource as non-compliant again.
You can set up alerts in Azure Policy to notify you whenever a resource falls out of compliance, enabling proactive management.
4. Remediation Tasks
If there are existing non-compliant resources that require specific configuration changes, you can use remediation tasks within Azure Policy to correct them. Remediation tasks apply the DeployIfNotExists or Modify effects retroactively, updating non-compliant resources to meet policy standards.
Remediation tasks are particularly useful for bringing older resources in line with new policies without manual reconfiguration.