Manage Azure policy using github

Naveen Kishore 0 Reputation points
2024-11-01T11:51:35.2866667+00:00

Dear community,

I'm looking for guidance on how to export azure policy into github and use the git hub actions to deploy the same.

I've tried to searching for relevant documentation. However, its not properly available.

With github export no longer an option, the documentation for exporting azure policies into github is very basic.

https://learn.microsoft.com/en-us/azure/governance/policy/how-to/export-resources

https://learn.microsoft.com/en-us/azure/governance/policy/concepts/policy-as-code

https://github.com/Azure/manage-azure-policy/blob/main/tutorial/azure-policy-as-code.md

The github documentation still points to this old approach which is no longer valid. New approach on how to do this activity is missing.

Kindly help me point in the right direction.

Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
939 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pavan Minukuri 915 Reputation points Microsoft Vendor
    2024-11-04T22:47:33.91+00:00

    Hi Naveen Kishore,
    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.
    To export Azure Policy definitions to GitHub and use GitHub Actions to deploy them, you can follow these general steps:

    1. Export the Azure Policy definitions to a JSON file. You can do this using the Azure Portal, Azure PowerShell, or Azure CLI. For example, you can use the following Azure PowerShell command to export a policy definition to a JSON file:
    Get-AzPolicyDefinition -Id <policy-definition-id> | ConvertTo-Json | Out-File <filename>.json
    

    Create a new GitHub repository to store the policy definitions.

    Add the JSON files containing the policy definitions to the GitHub repository.

    Create a GitHub Actions workflow to deploy the policy definitions to Azure. You can use the Azure CLI or Azure PowerShell to deploy the policy definitions. For example, you can use the following Azure PowerShell command to deploy a policy definition:

    New-AzPolicyDefinition -Name <policy-definition-name> -Policy <filename>.json -Mode All
    

    Configure the GitHub Actions workflow to run automatically when changes are made to the policy definitions in the GitHub repository.

    Test the GitHub Actions workflow to make sure that it deploys the policy definitions correctly.

    Note that this is a general outline of the steps involved in exporting Azure Policy definitions to GitHub and using GitHub Actions to deploy them. The specific details of the process may vary depending on your specific requirements and environment. You may need to modify the steps or use additional tools or services to achieve your goals.

    If you have any further queries, do let us know. If the Answer is helpful, please click "Accept Answer".


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.