How pvyver/policy-donotdelete works
Project Type and Purpose
• Type: Infrastructure-as-Code / automation toolkit for Azure Policy.
• Purpose: Define a “Do Not Allow Deletion” policy in JSON, then automate its creation (registration) and assignment (enforcement) in Azure using PowerShell scripts.
File Structure
• Top-level files:
• README.md – high-level description
• createPolicy.ps1 – script to register the policy definition
• assignPolicy.ps1 – script to assign the policy to a scope
• Directory:
• policies/doNotAllowDeletionPolicy.json – the policy definition itself
Extract Insights from README
• The README clearly states:
• Where the policy config lives (the JSON file).
• That createPolicy.ps1 registers the policy.
• That assignPolicy.ps1 assigns the registered policy to a subscription or resource group.
Main Components
a. Local/Dev Environment
• Policy source directory (Git repo)
• doNotAllowDeletionPolicy.json
• createPolicy.ps1
• assignPolicy.ps1
b. Execution Context
• PowerShell (Azure PowerShell module or Azure CLI)
• Azure Active Directory credential/token cache
c. Azure Management Plane
• Azure Resource Manager (ARM) REST API
• Azure Policy Service (Definition + Assignment resources)
d. Target Scope
• Subscription or Resource Group where the policy is enforced
Relationships & Data Flows
• The developer runs createPolicy.ps1
→ Script reads doNotAllowDeletionPolicy.json
→ Authenticates to Azure (AAD)
→ Calls ARM API to create/register a Policy Definition
• The developer runs assignPolicy.ps1
→ Optionally references the newly created definition
→ Calls ARM API to create a Policy Assignment at a specified scope
• Azure Policy Service enforces the rule in real time on resource‐create/update operations
Architectural Patterns & Principles
• Declarative vs. Imperative:
• JSON file – declarative policy specification
• PowerShell – imperative orchestration
• Separation of Concerns:
• One script for definition registration
• Another for assignment/enforcement
• Idempotency: Each script should check for existing definitions/assignments before creating new ones.
Technologies & Frameworks
• JSON (Azure Policy schema)
• PowerShell scripting
• Azure PowerShell Module / Azure CLI underneath
• Azure Resource Manager REST endpoints
Final Checklist for the Engineer
• Components and flows listed above.
• Notes/callouts for idempotency checks or parameterization in scripts.