# pala46/azure-inventory architecture

> Architecture diagram of the GitHub repository pala46/azure-inventory, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pala46/azure-inventory
- Repository: https://github.com/pala46/azure-inventory

## Overview

#### Purpose and Entry Point

This is a one-shot Azure inventory exporter. Its sole executable entry point, `azure_inventory.py`, authenticates through Azure SDK credential discovery, queries Azure Resource Graph (ARG) across visible or selected subscriptions, enriches resources locally, and writes CSV and optionally Excel output.

- `azure_inventory.py`
- `requirements.txt`

#### CLI and Run Configuration

`azure_inventory.py` owns argument parsing and controls the run scope: subscription filters, output format/path, required-tag policy, ARG page size, fast mode, and policy-query suppression. Constants near the top define organization-specific tag aliases, resource categories, environment name hints, and region display mappings.

The script is intentionally stateless: each invocation creates a timestamped inventory snapshot in the current directory or caller-specified output base path.

- `azure_inventory.py`

#### Azure Discovery Layer

Azure Resource Graph is the primary data plane, avoiding subscription-by-subscription ARM enumeration. The script queries resources plus supporting ARG datasets such as resource containers, policy states, diagnostic settings, and recovery/protection data. It pages graph results and reduces page size when payload limits are encountered.

Management-group ancestry, subscription names, tenant information, direct ARM resource fields, and several governance/operations signals are obtained in this layer.

- `azure_inventory.py`

#### Resource Normalization and Core Inventory Records

Raw ARG rows are transformed into a common record schema. This stage derives category from provider namespace, parses ARM IDs for parent/resource-group relationships, normalizes region names, extracts SKU/state/zone/identity details from properties, and emits `N/A` where a value cannot be determined.

The common schema is the boundary between Azure-specific query payloads and tabular export formats.

- `azure_inventory.py`

#### Governance Enrichment

Tag processing normalizes tag keys and scans them against configurable regex patterns to populate business metadata such as application, owner, environment, criticality, lifecycle, and classification. Environment can fall back to resource-group or resource-name hints. Required-tag compliance is alias-aware rather than relying solely on literal tag names.

Policy compliance is an optional separate ARG enrichment; policy-state results are consolidated so the worst observed state is assigned to each resource.

- `azure_inventory.py`

#### Network, Security, and Operations Correlation

The script builds in-memory relationships rather than issuing per-resource API calls. It cross-references public IPs, NICs, VMs, load balancers, VNets, subnets, and NSGs to derive public exposure, VNet/subnet placement, and network controls. Type-specific property inspection determines storage, disk, and CMK-related encryption status.

Additional graph-derived lookup sets associate resources with ARM diagnostic settings and Recovery Services protected-item sources. `--fast` bypasses property-driven network, access, and encryption enrichment.

- `azure_inventory.py`

#### Export Boundary and Dependencies

Final normalized/enriched records are serialized to CSV and, when `openpyxl` is installed, XLSX. Azure authentication supports Azure CLI login, service-principal environment variables, and managed identity through Azure SDK credential chaining. Required Azure permissions are Reader for inventory scope and Policy Insights read access for policy status.

- `azure_inventory.py`
- `requirements.txt`

Main entry points: [`azure_inventory.py`](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py) (Raw resource and lookup rows), [`requirements.txt`](https://github.com/pala46/azure-inventory/blob/main/requirements.txt) (Dependencies)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_run["Local execution"]
  node_cli["CLI and run config<br/>Python entry point<br/>[azure_inventory.py]"]
  node_constants["Org mappings and policies<br/>script constants<br/>[azure_inventory.py]"]
  node_requirements["Dependencies<br/>Python requirements<br/>[requirements.txt]"]
end

subgraph group_azure["Azure discovery"]
  node_credential{{"Azure credential chain<br/>Azure SDK auth<br/>[azure_inventory.py]"}}
  node_arg[("Azure Resource Graph<br/>Azure query plane<br/>[azure_inventory.py]")]
  node_arm_metadata["ARM and tenant metadata<br/>Azure management data<br/>[azure_inventory.py]"]
  node_raw_rows["Raw resource and lookup rows<br/>ARG payloads<br/>[azure_inventory.py]"]
end

subgraph group_processing["Inventory processing"]
  node_normalizer["Common record normalization<br/>record transformer<br/>[azure_inventory.py]"]
  node_tag_governance["Tag and policy enrichment<br/>governance correlator<br/>[azure_inventory.py]"]
  node_network_security["Network, security, and ops correlation<br/>in-memory correlator<br/>[azure_inventory.py]"]
  node_inventory[("Enriched inventory records<br/>common tabular schema<br/>[azure_inventory.py]")]
end

subgraph group_output["Export"]
  node_csv["Timestamped CSV snapshot<br/>CSV export<br/>[azure_inventory.py]"]
  node_xlsx["Optional XLSX snapshot<br/>Excel export<br/>[azure_inventory.py]"]
end

node_cli -->|"uses"| node_constants
node_cli -->|"initializes"| node_credential
node_credential -->|"authenticates queries"| node_arg
node_cli -->|"sets subscriptions and page size"| node_arg
node_arg -->|"returns paged datasets"| node_raw_rows
node_credential -->|"authenticates lookup"| node_arm_metadata
node_arm_metadata -->|"adds context"| node_raw_rows
node_raw_rows -->|"resource rows"| node_normalizer
node_constants -->|"category and region mappings"| node_normalizer
node_normalizer -->|"common records"| node_tag_governance
node_constants -->|"tag aliases and required policy"| node_tag_governance
node_raw_rows -->|"policy states"| node_tag_governance
node_tag_governance -->|"governed records"| node_network_security
node_raw_rows -->|"relationship lookup sets"| node_network_security
node_cli -.->|"fast mode may bypass"| node_network_security
node_network_security -->|"enriches records"| node_inventory
node_inventory -->|"serializes"| node_csv
node_inventory -->|"serializes"| node_xlsx
node_requirements -.->|"openpyxl enables"| node_xlsx

click node_cli "https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py"
click node_constants "https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py"
click node_requirements "https://github.com/pala46/azure-inventory/blob/main/requirements.txt"
click node_credential "https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py"
click node_arg "https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py"
click node_arm_metadata "https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py"
click node_raw_rows "https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py"
click node_normalizer "https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py"
click node_tag_governance "https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py"
click node_network_security "https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py"
click node_inventory "https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py"
click node_csv "https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py"
click node_xlsx "https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_constants,node_requirements toneBlue
class node_credential,node_arg,node_arm_metadata,node_raw_rows toneAmber
class node_normalizer,node_tag_governance,node_network_security,node_inventory toneMint
class node_csv,node_xlsx toneRose
```

## Components

### Local execution

- [CLI and run config](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py): Python entry point · Controls scope, output, paging, fast mode, and policy queries. · `azure_inventory.py`
- [Org mappings and policies](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py): script constants · Tag aliases, categories, environment hints, and region mappings. · `azure_inventory.py`
- [Dependencies](https://github.com/pala46/azure-inventory/blob/main/requirements.txt): Python requirements · Azure SDK and optional Excel dependency declarations. · `requirements.txt`

### Azure discovery

- [Azure credential chain](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py): Azure SDK auth · Uses CLI login, environment service principal, or managed identity. · `azure_inventory.py`
- [Azure Resource Graph](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py): Azure query plane · Paged cross-subscription resource and supporting dataset queries. · `azure_inventory.py`
- [ARM and tenant metadata](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py): Azure management data · Management ancestry, subscription names, tenant, and direct resource fields. · `azure_inventory.py`
- [Raw resource and lookup rows](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py): ARG payloads · Resources, containers, policy, diagnostics, and recovery data. · `azure_inventory.py`

### Inventory processing

- [Common record normalization](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py): record transformer · Parses ARM IDs and derives category, region, SKU, state, zones, and identity. · `azure_inventory.py`
- [Tag and policy enrichment](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py): governance correlator · Applies alias-aware tag compliance and worst policy state. · `azure_inventory.py`
- [Network, security, and ops correlation](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py): in-memory correlator · Derives exposure, placement, controls, encryption, diagnostics, and protection. · `azure_inventory.py`
- [Enriched inventory records](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py): common tabular schema · Azure-independent records ready for serialization. · `azure_inventory.py`

### Export

- [Timestamped CSV snapshot](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py): CSV export · Written to the current directory or requested output base path. · `azure_inventory.py`
- [Optional XLSX snapshot](https://github.com/pala46/azure-inventory/blob/main/azure_inventory.py): Excel export · Produced when openpyxl is available. · `azure_inventory.py`

## Connections

- CLI and run config → Org mappings and policies: uses
- CLI and run config → Azure credential chain: initializes
- Azure credential chain → Azure Resource Graph: authenticates queries
- CLI and run config → Azure Resource Graph: sets subscriptions and page size
- Azure Resource Graph → Raw resource and lookup rows: returns paged datasets
- Azure credential chain → ARM and tenant metadata: authenticates lookup
- ARM and tenant metadata → Raw resource and lookup rows: adds context
- Raw resource and lookup rows → Common record normalization: resource rows
- Org mappings and policies → Common record normalization: category and region mappings
- Common record normalization → Tag and policy enrichment: common records
- Org mappings and policies → Tag and policy enrichment: tag aliases and required policy
- Raw resource and lookup rows → Tag and policy enrichment: policy states
- Tag and policy enrichment → Network, security, and ops correlation: governed records
- Raw resource and lookup rows → Network, security, and ops correlation: relationship lookup sets
- CLI and run config → Network, security, and ops correlation: fast mode may bypass
- Network, security, and ops correlation → Enriched inventory records: enriches records
- Enriched inventory records → Timestamped CSV snapshot: serializes
- Enriched inventory records → Optional XLSX snapshot: serializes
- Dependencies → Optional XLSX snapshot: openpyxl enables
