question

vasudevareddy-0616 avatar image
vasudevareddy-0616 asked ·

Export azure policies

HI Team,

I have a requirement to export all Azure policy definitions and policy assignments to a json file, later we want to automate all these from CI/CD pipelines.

Can you please help me on how to achieve this

Thanks
Vasudeva Reddy

azure-policy
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DCtheGeek avatar image
DCtheGeek answered ·

The SDK for Azure Policy supports this action.

There are SDK for other languages also, such as REST API, .NET, JavaScript, and Python.

All of the Azure CLI and Azure PowerShell operations and cmdlets can be run with no parameters to get all available objects (built-ins and custom for definitions) that the authenticated user has access to without any parameters.

![13936-image.png]

Then you can loop through the results and convert them to JSON files:
13905-image.png

This approach also means you could filter the resulting definitions if you didn't want a specific category or something along those lines:
13920-image.png



image.png (37.6 KiB)
image.png (61.7 KiB)
image.png (7.2 KiB)
Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.