Azure Enterprise Policy as Code (EPAC)
In the ever-evolving landscape of cloud computing, governance and compliance stand as pillars of enterprise architecture. Azure’s Enterprise Policy as Code (EPAC) framework emerges as a beacon of structure and automation, enabling organizations to define, assign, and manage their cloud resources with unprecedented precision and control.
EPAC is not just a tool; it’s a paradigm shift. It encapsulates the best practices of infrastructure as code (IaC) and extends them to policy management, allowing you to treat your policies as you would any other code. With EPAC, policies become version-controlled, testable, and deployable artifacts, ensuring consistency and compliance across your Azure environments. 🔥
In this case, I’ve designed a Policy Assignment to audit virtual machines without disaster recovery (DR) measures in place. This assignment, along with new PolicyAssignments, PolicyDefinitions, and PolicySetDefinitions, undergoes thorough testing within the “ctEpacDev” management scope. Once validated, they will be systematically deployed to the “ctEpacProd” management scope. Utilizing the Enterprise Policy as Code (EPAC) framework, we streamline this process by exporting from “ctEpacDev” and deploying to “ctEpacProd,” effectively bypassing manual operations.

As you can see the Policy Assignment is in-place at the “ctEpacDev”-MGMT-scope. Lets export this baby and get it in the “ctEpacProd” MGMT-scope.

We need the required PowerShell module for EPAC. Thats why we are going to install it (pwsh 7.0 is minimum):
Install-Module EnterprisePolicyAsCode -Scope CurrentUser

Now lets prepare our environment by letting EPAC create DefinitionsRootFolders. This can be done via the command:
New-EPACDefinitionFolder -DefinitionsRootFolder Definitions

Afterthat I prepped the global-settings.jsonc. This file is stored in my Git.

We now need to export the Policy Assignment to Code. That’s why I connected to my Azure test-subscription and validated the connection, to ensure I’ve got the required permissions.

This creates a folder called “Output” as expected. With all our exported policies. There is also a policy-ownership.csv-file. You can use this as report to see what all policies are and look through the .JSON-files in the folders depending on your export🔥
Export-AzPolicyResources -DefinitionsRootFolder .\Definitions -OutputFolder Output

Next, we need to create a plan for our policies. We’ll make one using the policies from the Export folder, based on what we have in the Dev environment.
Build-DeploymentPlans -DefinitionsRootFolder Definitions -OutputFolder Output

Because our Policy Plan is based on the Dev-Environment and I want to deploy to my clean Prod Management I copied the policy plan and added the PacEnvironment for Prod.

Before deployment I had no Policy Assignments at “ctEpacProd”.

After deployment, you can see the expected Policy Assignment✅

As demonstrated, the Enterprise Policy as Code (EPAC) framework is a powerful tool for managing Azure policies. In this demonstration, we showcased a single Policy Assignment, but rest assured, EPAC can handle multiple assignments with ease. For a robust deployment process, integrating Azure DevOps or GitHub for continuous integration and delivery (CI/CD) is highly recommended. For simplicity, this demo utilized PowerShell for deployment. Thank you for following along. If you found this helpful, a round of applause is much appreciated. Until next time!❤️