How to remediate non-compliant resource through python sdk

Mansi Sharma 1 Reputation point
2021-07-23T13:25:35.283+00:00

Hi,
I am creating policy definitions through Python SDK for creating diagnostic setting for all the resources of a particular type and I want to remediate non-compliant resources. Through UI I am able to create remediation task but when do it through SDK it is not working.. below is the code I used for creating remediation task ,can anyone point out what is that I am missing in this code?

remediation=Remediation(policy_assignment_id=policyAssignRes.id,policy_definition_reference_id=policyDefinitionRes.id,resource_discovery_mode=ResourceDiscoveryMode.EXISTING_NON_COMPLIANT,filters=RemediationFilters(locations=list("eastus2")))
remediationOptr=policyInsightsClient.remediations
remediationOptrRes=remediationOptr.create_or_update_at_subscription(remediation_name="Remidiations task for xyz resource", parameters=remediation)

Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
867 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,423 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 18,756 Reputation points
    2022-02-18T18:15:52.867+00:00

    @Mansi Sharma Here is sample code on how to remediate non-compliant resources using python sdk. Do check it out and revert if you have further questions.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.