# thedevopsjedi/azure-pim architecture

> Architecture diagram of the GitHub repository thedevopsjedi/azure-pim, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thedevopsjedi/azure-pim
- Repository: https://github.com/thedevopsjedi/azure-pim

## Overview

##### Project type and purpose
- This is a small automation/orchestration tool (a PowerShell script) that configures Azure Privileged Identity Management (PIM) for a given subscription and resource group.
- It’s intended to be run interactively or from an Azure DevOps pipeline to enable/disable role eligibility on Azure Resource Groups via the (undocumented) Azure PIM REST API.

##### File structure
- Top level contains:
- PIMConfigureEligibleAzureResource.ps1 – the single PowerShell script implementing the logic
- README.md – usage instructions and background
- .gitignore, LICENSE – project metadata
- No build system, no frontend/backend separation; this is a stand-alone script.

##### README for additional insights
- Authenticates using Connect-AzAccount (Azure PowerShell module).
- Uses raw HTTP calls to the Azure PIM API (because Terraform/AzCLI/PS modules don’t yet support PIM).
- Offers switches:
- ‑deleteAssignmentOnly (cleanup mode)
- ‑exportFiles (dump JSON before/after)

##### Main components and interactions
a. User / DevOps Pipeline
– Trigger: runs the PowerShell script with parameters
b. Authentication Layer
– Connect-AzAccount → Azure AD OAuth 2.0 endpoint
c. Script Core Logic (PIMConfigureEligibleAzureResource.ps1)
– Builds REST calls (role management policy, eligible assignment)
– Handles deletion-only and export-files modes
d. Azure PIM REST API
– Receives HTTP requests to assign/unassign eligible roles
– Returns JSON responses
e. Azure Resources
– Target Subscription → Resource Group(s)
– Azure AD group or service principal (memberObjectId)
f. Optional: Local File System (when ‑exportFiles)
– JSON before and after configuration

##### Architectural patterns and principles
- Single-entry automation script
- Clear separation of concerns:
1) Authentication
2) Request construction & API interaction
3) Optional export/persistence
- Idempotent design: can delete only or apply full config

– “Create/Update Role Management Policy”
– “Assign Eligible Role”
– “Delete Assignment (if cleanup mode)”
– Local (script + filesystem): green
– Trigger (user/pipeline): orange
– Azure cloud services: blue

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Trigger
    User["User / DevOps Pipeline"]:::trigger
    click User "https://github.com/thedevopsjedi/azure-pim/blob/main/./PIMConfigureEligibleAzureResource.ps1"

    %% Core Script
    Script["PowerShell Script: PIMConfigureEligibleAzureResource.ps1"]:::local
    click Script "https://github.com/thedevopsjedi/azure-pim/blob/main/./PIMConfigureEligibleAzureResource.ps1"

    %% Authentication
    Auth["Azure AD Authentication Endpoint"]:::cloud
    click Auth "https://github.com/thedevopsjedi/azure-pim/blob/main/./PIMConfigureEligibleAzureResource.ps1"

    %% API Interaction
    PIMAPI["Azure PIM REST API"]:::cloud
    click PIMAPI "https://github.com/thedevopsjedi/azure-pim/blob/main/./PIMConfigureEligibleAzureResource.ps1"

    %% Azure Resources
    Resources["Azure Subscription & Resource Group"]:::cloud

    %% Local File System
    FS["Local File System (JSON export)"]:::local
    click FS "https://github.com/thedevopsjedi/azure-pim/blob/main/./PIMConfigureEligibleAzureResource.ps1"

    %% Project Metadata
    subgraph "Project Metadata"
        README["README.md"]:::meta
        Gitignore[".gitignore"]:::meta
        License["LICENSE"]:::meta
    end
    click README "https://github.com/thedevopsjedi/azure-pim/blob/main/./README.md"
    click Gitignore "https://github.com/thedevopsjedi/azure-pim/blob/main/./.gitignore"
    click License "https://github.com/thedevopsjedi/azure-pim/tree/main/./LICENSE"

    %% Relationships
    User -->|"execute script"| Script
    Script -->|"Connect-AzAccount (OAuth2)"| Auth
    Script -->|"PUT/DELETE /roleManagement/*"| PIMAPI
    PIMAPI -->|"role assignment operations"| Resources
    Script -->|"–exportFiles: dump JSON"| FS

    %% Styles
    classDef trigger fill:#FFA500,stroke:#333,stroke-width:1px
    classDef local   fill:#9f6,stroke:#333,stroke-width:1px
    classDef cloud   fill:#6cf,stroke:#333,stroke-width:1px
    classDef meta    fill:#ccc,stroke:#333,stroke-width:1px
```
