# sm-joe/tf-iam architecture

> Architecture diagram of the GitHub repository sm-joe/tf-iam, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sm-joe/tf-iam
- Repository: https://github.com/sm-joe/tf-iam

## Overview

tf-iam is a Python CLI for deriving reviewable, least-privilege AWS IAM policy candidates from Terraform configuration or saved plans. The main workflow enters through the CLI, analyzes configuration and lifecycle operations, resolves provider and resource context, then derives scoped permissions for reporting or policy generation. Separate CLI commands support comparison, policy packing, catalog/provider audits, IAM validation, and CloudTrail runtime auditing. Edges follow shown imports and documented command capabilities; unsampled implementation details are not inferred.

Main entry points: [`tfiam/scan.py`](https://github.com/sm-joe/tf-iam/blob/main/tfiam/scan.py) (Configuration scan), [`tfiam/cli.py`](https://github.com/sm-joe/tf-iam/blob/main/tfiam/cli.py) (Command interface), [`tfiam/catalog_loader.py`](https://github.com/sm-joe/tf-iam/blob/main/tfiam/catalog_loader.py) (AWS permissions catalog), [`tfiam/provider_audit.py`](https://github.com/sm-joe/tf-iam/blob/main/tfiam/provider_audit.py) (Provider audit)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and reporting"]
  node_cli["Command interface<br/>[cli.py]"]
  node_tables["Report rendering<br/>[table_output.py]"]
end

subgraph group_analysis["Terraform analysis"]
  node_scan["Configuration scan<br/>[scan.py]"]
  node_plan["Saved-plan parser<br/>[plan.py]"]
  node_resolver["Static resolver<br/>[resolver.py]"]
  node_provider_context["Provider contexts"]
  node_versioning["Provider versioning<br/>[versioning.py]"]
  node_plan_buckets["Bucket recovery<br/>[plan_buckets.py]"]
  node_plan_roles["Role recovery<br/>[plan_roles.py]"]
  node_dependencies["Dependency discovery<br/>[dependencies.py]"]
end

subgraph group_permissions["Permission modeling"]
  node_catalog[("AWS permissions catalog<br/>[catalog_loader.py]")]
  node_plan_network["Network plan scope<br/>[plan_network.py]"]
  node_action_scope["Action-specific scopes<br/>[action_scope.py]"]
  node_service_scope["Service scopes<br/>[service_scope.py]"]
  node_expanded_scope["Expanded scope<br/>[expanded_scope.py]"]
  node_optimization["Grant optimization<br/>[optimization.py]"]
end

subgraph group_review["Review and integrations"]
  node_risk["Risk assessment<br/>[risk.py]"]
  node_comparison["Policy comparison<br/>[comparison.py]"]
  node_lifecycle["Lifecycle separation<br/>[lifecycle.py]"]
  node_policy_size["Policy packing<br/>[policy_size.py]"]
  node_authorization["Authorization metadata audit<br/>[authorization.py]"]
  node_provider_audit["Provider audit<br/>[provider_audit.py]"]
  node_evidence_audit["Evidence audit<br/>[evidence_audit.py]"]
  node_cloud["AWS and CloudTrail<br/>[cloud.py]"]
end

node_user(("Security engineer"))

node_user -->|"runs commands"| node_cli
node_cli -->|"invokes scan"| node_scan
node_scan -->|"parses plans"| node_plan
node_scan -->|"resolves values"| node_resolver
node_scan -->|"selects contexts"| node_provider_context
node_scan -->|"selects version"| node_versioning
node_scan -->|"loads mappings"| node_catalog
node_scan -->|"recovers buckets"| node_plan_buckets
node_scan -->|"recovers roles"| node_plan_roles
node_scan -->|"discovers dependencies"| node_dependencies
node_scan -->|"uses network scope"| node_plan_network
node_scan -->|"uses action scopes"| node_action_scope
node_scan -->|"uses service scopes"| node_service_scope
node_scan -->|"expands scopes"| node_expanded_scope
node_scan -->|"optimizes grants"| node_optimization
node_scan -->|"assesses risks"| node_risk
node_cli -->|"renders reports"| node_tables
node_cli -->|"compares grants"| node_comparison
node_cli -->|"splits candidates"| node_lifecycle
node_cli -->|"packs policies"| node_policy_size
node_cli -->|"audits metadata"| node_authorization
node_cli -->|"audits provider"| node_provider_audit
node_cli -->|"audits evidence"| node_evidence_audit
node_cli -->|"runs AWS checks"| node_cloud
node_catalog -->|"selects overrides"| node_versioning
node_authorization -->|"checks mappings"| node_catalog
node_provider_audit -->|"checks mappings"| node_catalog
node_provider_audit -->|"checks versions"| node_versioning
node_cloud -->|"uses metadata"| node_authorization

click node_cli "https://github.com/sm-joe/tf-iam/blob/main/tfiam/cli.py"
click node_tables "https://github.com/sm-joe/tf-iam/blob/main/tfiam/table_output.py"
click node_scan "https://github.com/sm-joe/tf-iam/blob/main/tfiam/scan.py"
click node_plan "https://github.com/sm-joe/tf-iam/blob/main/tfiam/plan.py"
click node_resolver "https://github.com/sm-joe/tf-iam/blob/main/tfiam/resolver.py"
click node_provider_context "https://github.com/sm-joe/tf-iam/blob/main/tfiam/provider_context.py"
click node_versioning "https://github.com/sm-joe/tf-iam/blob/main/tfiam/versioning.py"
click node_catalog "https://github.com/sm-joe/tf-iam/blob/main/tfiam/catalog_loader.py"
click node_plan_buckets "https://github.com/sm-joe/tf-iam/blob/main/tfiam/plan_buckets.py"
click node_plan_roles "https://github.com/sm-joe/tf-iam/blob/main/tfiam/plan_roles.py"
click node_dependencies "https://github.com/sm-joe/tf-iam/blob/main/tfiam/dependencies.py"
click node_plan_network "https://github.com/sm-joe/tf-iam/blob/main/tfiam/plan_network.py"
click node_action_scope "https://github.com/sm-joe/tf-iam/blob/main/tfiam/action_scope.py"
click node_service_scope "https://github.com/sm-joe/tf-iam/blob/main/tfiam/service_scope.py"
click node_expanded_scope "https://github.com/sm-joe/tf-iam/blob/main/tfiam/expanded_scope.py"
click node_risk "https://github.com/sm-joe/tf-iam/blob/main/tfiam/risk.py"
click node_comparison "https://github.com/sm-joe/tf-iam/blob/main/tfiam/comparison.py"
click node_lifecycle "https://github.com/sm-joe/tf-iam/blob/main/tfiam/lifecycle.py"
click node_policy_size "https://github.com/sm-joe/tf-iam/blob/main/tfiam/policy_size.py"
click node_authorization "https://github.com/sm-joe/tf-iam/blob/main/tfiam/authorization.py"
click node_provider_audit "https://github.com/sm-joe/tf-iam/blob/main/tfiam/provider_audit.py"
click node_evidence_audit "https://github.com/sm-joe/tf-iam/blob/main/tfiam/evidence_audit.py"
click node_cloud "https://github.com/sm-joe/tf-iam/blob/main/tfiam/cloud.py"
click node_optimization "https://github.com/sm-joe/tf-iam/blob/main/tfiam/optimization.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_tables toneBlue
class node_scan,node_plan,node_resolver,node_provider_context,node_versioning,node_plan_buckets,node_plan_roles,node_dependencies toneAmber
class node_catalog,node_plan_network,node_action_scope,node_service_scope,node_expanded_scope,node_optimization toneMint
class node_risk,node_comparison,node_lifecycle,node_policy_size,node_authorization,node_provider_audit,node_evidence_audit,node_cloud toneRose
class node_user toneIndigo
```

## Components

### CLI and reporting

- [Command interface](https://github.com/sm-joe/tf-iam/blob/main/tfiam/cli.py): `tfiam/cli.py`
- [Report rendering](https://github.com/sm-joe/tf-iam/blob/main/tfiam/table_output.py): `tfiam/table_output.py`

### Terraform analysis

- [Configuration scan](https://github.com/sm-joe/tf-iam/blob/main/tfiam/scan.py): `tfiam/scan.py`
- [Saved-plan parser](https://github.com/sm-joe/tf-iam/blob/main/tfiam/plan.py): `tfiam/plan.py`
- [Static resolver](https://github.com/sm-joe/tf-iam/blob/main/tfiam/resolver.py): `tfiam/resolver.py`
- [Provider contexts](https://github.com/sm-joe/tf-iam/blob/main/tfiam/provider_context.py): `tfiam/provider_context.py`
- [Provider versioning](https://github.com/sm-joe/tf-iam/blob/main/tfiam/versioning.py): `tfiam/versioning.py`
- [Bucket recovery](https://github.com/sm-joe/tf-iam/blob/main/tfiam/plan_buckets.py): `tfiam/plan_buckets.py`
- [Role recovery](https://github.com/sm-joe/tf-iam/blob/main/tfiam/plan_roles.py): `tfiam/plan_roles.py`
- [Dependency discovery](https://github.com/sm-joe/tf-iam/blob/main/tfiam/dependencies.py): `tfiam/dependencies.py`

### Permission modeling

- [AWS permissions catalog](https://github.com/sm-joe/tf-iam/blob/main/tfiam/catalog_loader.py): `tfiam/catalog_loader.py`
- [Network plan scope](https://github.com/sm-joe/tf-iam/blob/main/tfiam/plan_network.py): `tfiam/plan_network.py`
- [Action-specific scopes](https://github.com/sm-joe/tf-iam/blob/main/tfiam/action_scope.py): `tfiam/action_scope.py`
- [Service scopes](https://github.com/sm-joe/tf-iam/blob/main/tfiam/service_scope.py): `tfiam/service_scope.py`
- [Expanded scope](https://github.com/sm-joe/tf-iam/blob/main/tfiam/expanded_scope.py): `tfiam/expanded_scope.py`
- [Grant optimization](https://github.com/sm-joe/tf-iam/blob/main/tfiam/optimization.py): `tfiam/optimization.py`

### Review and integrations

- [Risk assessment](https://github.com/sm-joe/tf-iam/blob/main/tfiam/risk.py): `tfiam/risk.py`
- [Policy comparison](https://github.com/sm-joe/tf-iam/blob/main/tfiam/comparison.py): `tfiam/comparison.py`
- [Lifecycle separation](https://github.com/sm-joe/tf-iam/blob/main/tfiam/lifecycle.py): `tfiam/lifecycle.py`
- [Policy packing](https://github.com/sm-joe/tf-iam/blob/main/tfiam/policy_size.py): `tfiam/policy_size.py`
- [Authorization metadata audit](https://github.com/sm-joe/tf-iam/blob/main/tfiam/authorization.py): `tfiam/authorization.py`
- [Provider audit](https://github.com/sm-joe/tf-iam/blob/main/tfiam/provider_audit.py): `tfiam/provider_audit.py`
- [Evidence audit](https://github.com/sm-joe/tf-iam/blob/main/tfiam/evidence_audit.py): `tfiam/evidence_audit.py`
- [AWS and CloudTrail](https://github.com/sm-joe/tf-iam/blob/main/tfiam/cloud.py): `tfiam/cloud.py`

### Other components

- **Security engineer**

## Connections

- Security engineer → Command interface: runs commands (evidence: `README.md`)
- Command interface → Configuration scan: invokes scan (evidence: `tfiam/cli.py`)
- Configuration scan → Saved-plan parser: parses plans (evidence: `tfiam/scan.py`)
- Configuration scan → Static resolver: resolves values (evidence: `tfiam/scan.py`)
- Configuration scan → Provider contexts: selects contexts (evidence: `tfiam/scan.py`)
- Configuration scan → Provider versioning: selects version (evidence: `tfiam/scan.py`)
- Configuration scan → AWS permissions catalog: loads mappings (evidence: `tfiam/scan.py`)
- Configuration scan → Bucket recovery: recovers buckets (evidence: `tfiam/scan.py`)
- Configuration scan → Role recovery: recovers roles (evidence: `tfiam/scan.py`)
- Configuration scan → Dependency discovery: discovers dependencies (evidence: `tfiam/scan.py`)
- Configuration scan → Network plan scope: uses network scope (evidence: `tfiam/scan.py`)
- Configuration scan → Action-specific scopes: uses action scopes (evidence: `tfiam/scan.py`)
- Configuration scan → Service scopes: uses service scopes (evidence: `tfiam/scan.py`)
- Configuration scan → Expanded scope: expands scopes (evidence: `tfiam/scan.py`)
- Configuration scan → Grant optimization: optimizes grants (evidence: `tfiam/scan.py`)
- Configuration scan → Risk assessment: assesses risks (evidence: `tfiam/scan.py`)
- Command interface → Report rendering: renders reports (evidence: `tfiam/cli.py`)
- Command interface → Policy comparison: compares grants (evidence: `tfiam/cli.py`)
- Command interface → Lifecycle separation: splits candidates (evidence: `tfiam/cli.py`)
- Command interface → Policy packing: packs policies (evidence: `tfiam/cli.py`)
- Command interface → Authorization metadata audit: audits metadata (evidence: `tfiam/cli.py`)
- Command interface → Provider audit: audits provider (evidence: `tfiam/cli.py`)
- Command interface → Evidence audit: audits evidence (evidence: `tfiam/cli.py`)
- Command interface → AWS and CloudTrail: runs AWS checks (evidence: `tfiam/cli.py`)
- AWS permissions catalog → Provider versioning: selects overrides (evidence: `tfiam/catalog_loader.py`)
- Authorization metadata audit → AWS permissions catalog: checks mappings (evidence: `tfiam/authorization.py`)
- Provider audit → AWS permissions catalog: checks mappings (evidence: `tfiam/provider_audit.py`)
- Provider audit → Provider versioning: checks versions (evidence: `tfiam/provider_audit.py`)
- AWS and CloudTrail → Authorization metadata audit: uses metadata (evidence: `tfiam/cloud.py`)
